OpenBI Docs Buy

NETWORK.CYCLES OpenBI

Round trips: cycles in the network, as money moving in a circle.

Group: Networks. OpenBI’s own: DAX has no function of this name.

Syntax

NETWORK.CYCLES ( <links>, <from>, <to> [, <weight>] [, <directed>] [, <longest>] )
ParameterTypeDescription
linksTableThe rows that make the network, one link a row: a table of the model or a table expression, as the filters leave it.
fromExpression
evaluated for each row
One end of each row's link, such as a payer, a customer or a place.
toExpression
evaluated for each row
The other end of each row's link.
weightExpression
optional, evaluated for each row
How heavy each row's link is, such as an amount or a count; never negative. Left out, or given as the constant BLANK (), every row weighs 1.
directedBoolean
optional
TRUE when each link runs one way, from its first end to its second. FALSE or left out, a link works both ways.
longestWhole number
optional
The most links a cycle may have, from 2 to 20: 6 when left out.

Returns

Table. A row a step of each cycle. Its columns: Cycle and Length; Step, Node and Next; Weight and Least weight.

Remarks

  • A cycle goes from node to node along the links and comes back to where it started, visiting no node twice. Each cycle is listed once, its steps in order: Node pays Next, and Weight is that link's weight.
  • Least weight is the smallest weight on the cycle, on every row of it: the most that can have gone all the way round.
  • Directed, a cycle follows the links' direction and can be as short as 2 (A pays B, B pays A). Not directed, a cycle has at least 3 links.
  • At most 10,000 cycles are listed. On a large, dense network keep longest small, or filter the rows first.
  • Several rows between the same two nodes make one link, and their weights add up. Without a weight each row adds 1, so a pair that appears three times weighs 3.

Compared with DAX

An OpenBI function: DAX has none like it, so a measure or query that uses it works in OpenBI only, not in Power BI or Analysis Services.

Examples

Money going round

Two rings: A, B and C, and C, D and E. At most 60 can have gone round the first, 30 the second.

EVALUATE
VAR Payments =
    DATATABLE (
        "Payer", STRING, "Payee", STRING, "Amount", INTEGER,
        {
            { "A", "B", 100 }, { "B", "C", 80 }, { "C", "A", 60 }, { "C", "D", 50 },
            { "D", "E", 40 }, { "E", "C", 30 }, { "E", "F", 20 }
        }
    )
RETURN
    SELECTCOLUMNS (
        NETWORK.CYCLES ( Payments, [Payer], [Payee], [Amount], TRUE ),
        "Cycle", [Cycle],
        "Step", [Step],
        "Node", [Node],
        "Next", [Next],
        "Weight", [Weight],
        "Least weight", [Least weight]
    )
CycleStepNodeNextWeightLeast weight
11AB10060
12BC8060
13CA6060
21CD5030
22DE4030
23EC3030

Triangles of friends

EVALUATE
VAR Links =
    DATATABLE (
        "From", STRING, "To", STRING,
        {
            { "Ann", "Bo" }, { "Ann", "Cy" }, { "Bo", "Cy" }, { "Cy", "Di" },
            { "Di", "Ed" }, { "Ed", "Fay" }, { "Di", "Fay" }, { "Fay", "Gus" }
        }
    )
RETURN
    SELECTCOLUMNS (
        NETWORK.CYCLES ( Links, [From], [To] ),
        "Cycle", [Cycle],
        "Length", [Length],
        "Node", [Node]
    )
CycleLengthNode
13Ann
13Bo
13Cy
23Di
23Ed
23Fay

NETWORK.TRIADS, NETWORK.CLIQUES, NETWORK.REACH, NETWORK.FLOW.

Open Graph, OpenBI's graph library, does the work: simple_cycles. See the OAX network functions and Open Graph.

Last updated · OpenBI Studio 0.3.78