OpenBI Docs Buy

PATHITEM

The key at a position in a PATH text, counted from the top.

Group: Parent and child. Compatible with DAX.

Syntax

PATHITEM ( <path>, <position> [, <type>] )
ParameterTypeDescription
pathTextA path as PATH writes it: keys separated by |.
positionWhole numberWhich key, counted from the top: 1 is the top of the tree.
typeKeyword
optional
TEXT (or 0) to get the key as text, which is what you get when it is left out; INTEGER (or 1) to get a whole number. Any other value is an error.

Returns

Text or whole number. The key at that position, or BLANK when the path has no key there.

Remarks

  • A position past the end of the path, 0 or a negative one gives BLANK, not an error, so a column per level simply stays blank below the rows that are not that deep.
  • A position with a fraction is rounded, a half away from zero.
  • With INTEGER, a key with decimals is rounded to a whole number, a half to the even one (2.5 gives 2, 3.5 gives 4); a key that is no number, empty text included, is an error.
  • Ask for INTEGER when the key is looked up in a column of whole numbers, as LOOKUPVALUE does in example 2.

Examples

The keys of a path, from the top

EVALUATE
ROW (
    "1st", PATHITEM ( "1|20|21", 1 ),
    "2nd", PATHITEM ( "1|20|21", 2, INTEGER ),
    "3rd", PATHITEM ( "1|20|21", 3 ),
    "4th", PATHITEM ( "1|20|21", 4 )
)
1st2nd3rd4th
12021(blank)

The tree as levels

A column for each level, the name looked up from the key: the usual way to show a parent-child tree in a matrix.

EVALUATE
VAR Levels =
    ADDCOLUMNS ( Companies, "Path", PATH ( Companies[Key], Companies[Parent] ) )
RETURN
    SELECTCOLUMNS (
        Levels,
        "Company", Companies[Company],
        "Level 1", LOOKUPVALUE ( Companies[Company], Companies[Key], PATHITEM ( [Path], 1, INTEGER ) ),
        "Level 2", LOOKUPVALUE ( Companies[Company], Companies[Key], PATHITEM ( [Path], 2, INTEGER ) ),
        "Level 3", LOOKUPVALUE ( Companies[Company], Companies[Key], PATHITEM ( [Path], 3, INTEGER ) )
    )
ORDER BY [Level 1], [Level 2], [Level 3]
CompanyLevel 1Level 2Level 3
Example Brewery GroupExample Brewery Group(blank)(blank)
BrewingExample Brewery GroupBrewing(blank)
Bergen plantExample Brewery GroupBrewingBergen plant
Oslo plantExample Brewery GroupBrewingOslo plant
Trondheim plantExample Brewery GroupBrewingTrondheim plant
DistributionExample Brewery GroupDistribution(blank)
Alnabru depotExample Brewery GroupDistributionAlnabru depot
Example Brewery HoldingExample Brewery GroupExample Brewery Holding(blank)

A type that is neither TEXT nor INTEGER

EVALUATE
ROW ( "Type 2", PATHITEM ( "1|20|21", 1, 2 ) )

Result: an error.

PATHITEMREVERSE, PATH, PATHLENGTH, LOOKUPVALUE.

Last updated · OpenBI Studio 0.3.74