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>] )
| Parameter | Type | Description |
|---|---|---|
links | Table | The rows that make the network, one link a row: a table of the model or a table expression, as the filters leave it. |
from | Expression evaluated for each row | One end of each row's link, such as a payer, a customer or a place. |
to | Expression evaluated for each row | The other end of each row's link. |
weight | Expression 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. |
directed | Boolean optional | TRUE when each link runs one way, from its first end to its second. FALSE or left out, a link works both ways. |
longest | Whole 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
longestsmall, 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]
)
| Cycle | Step | Node | Next | Weight | Least weight |
|---|---|---|---|---|---|
| 1 | 1 | A | B | 100 | 60 |
| 1 | 2 | B | C | 80 | 60 |
| 1 | 3 | C | A | 60 | 60 |
| 2 | 1 | C | D | 50 | 30 |
| 2 | 2 | D | E | 40 | 30 |
| 2 | 3 | E | C | 30 | 30 |
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]
)
| Cycle | Length | Node |
|---|---|---|
| 1 | 3 | Ann |
| 1 | 3 | Bo |
| 1 | 3 | Cy |
| 2 | 3 | Di |
| 2 | 3 | Ed |
| 2 | 3 | Fay |
Related functions
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.