OpenBI Docs Buy

NETWORK.PATH OpenBI

The shortest path, in hops, between two nodes.

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

Syntax

NETWORK.PATH ( <links>, <from>, <to>, <source>, <target> [, <directed>] )
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.
sourceValueThe node the path starts at.
targetValueThe node the path ends at.
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.

Returns

Table. A row a step of the path, with the columns Step (1 the source) and Node.

Remarks

  • The path is a shortest one in hops: the fewest links. When several are as short, one of them is given, the same one whatever the order of the rows.
  • No weight is taken: every link is one hop.
  • When the target can't be reached, or either end given is no node of the network, the result is an empty table. From a node to itself, it is one row.
  • Directed, the path follows each link only from its first end to its second.

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

From Ann to Gus

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
    NETWORK.PATH ( Links, [From], [To], "Ann", "Gus" )
StepNode
1Ann
2Cy
3Di
4Fay
5Gus

Across town in short hops

From Skøyen to Kampen using only roads of six minutes or less.

EVALUATE
NETWORK.PATH (
    FILTER ( Distances, Distances[Minutes] <= 6 ),
    Distances[From], Distances[To],
    "Shop Skøyen", "Shop Kampen"
)
StepNode
1Shop Skøyen
2Shop Frogner
3Shop Majorstuen
4Shop St. Hanshaugen
5Shop Grünerløkka
6Shop Tøyen
7Shop Kampen

No way back

F receives money but pays nobody, so following the payments there is no path from F to A.

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
    NETWORK.PATH ( Payments, [Payer], [Payee], "F", "A", TRUE )
StepNode

NETWORK.REACH, NETWORK.FLOW, NETWORK.NODES.

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

Last updated · OpenBI Studio 0.3.78