Short answer: a parent-child table has one row per item and a column with the parent's ID: employees and their managers, accounts and their parent accounts. PATH ( id, parent_id ) returns the chain from the top down as text ("1|4|9"). From it, PATHLENGTH gives the depth, PATHITEM ( path, n ) the ID at level n, PATHITEMREVERSE counts from the bottom, and PATHCONTAINS ( path, id ) tests whether an ID is in the chain. Use them to build level columns (Level 1, Level 2, Level 3) for a matrix hierarchy, and for manager security.
Power BI hierarchies need one column per level. Org charts and account trees come as parent-child pairs with any depth. The PATH functions turn one into the other.
What do the functions return?
| Employee ID | Name | Manager ID | PATH | PATHLENGTH | Level 1 | Level 2 | Level 3 |
|---|---|---|---|---|---|---|---|
| 1 | Sara (CEO) | 1 | 1 | Sara | Sara | Sara | |
| 4 | Omar | 1 | 1|4 | 2 | Sara | Omar | Omar |
| 9 | Lena | 4 | 1|4|9 | 3 | Sara | Omar | Lena |
| 7 | Tom | 1 | 1|7 | 2 | Sara | Tom | Tom |
| Function | Returns | Example |
|---|---|---|
| PATH ( id, parent ) | the chain of IDs as text, top first | PATH ( Employee[Employee ID], Employee[Manager ID] ) |
| PATHLENGTH ( path ) | the number of items | PATHLENGTH ( Employee[Path] ) |
| PATHITEM ( path, n [, type] ) | the item at position n from the top | PATHITEM ( Employee[Path], 2, INTEGER ) |
| PATHITEMREVERSE ( path, n [, type] ) | the item at position n from the bottom | PATHITEMREVERSE ( Employee[Path], 1 ) |
| PATHCONTAINS ( path, item ) | TRUE if the item is in the path | PATHCONTAINS ( Employee[Path], 4 ) |
How do you build level columns?
-- calculated columns on Employee
Path = PATH ( Employee[Employee ID], Employee[Manager ID] )
Depth = PATHLENGTH ( Employee[Path] )
Level 1 =
LOOKUPVALUE ( Employee[Name], Employee[Employee ID], PATHITEM ( Employee[Path], 1, INTEGER ) )
Level 2 =
VAR Id = PATHITEM ( Employee[Path], 2, INTEGER )
RETURN IF ( ISBLANK ( Id ), Employee[Level 1], LOOKUPVALUE ( Employee[Name], Employee[Employee ID], Id ) )
Level 3 =
VAR Id = PATHITEM ( Employee[Path], 3, INTEGER )
RETURN IF ( ISBLANK ( Id ), Employee[Level 2], LOOKUPVALUE ( Employee[Name], Employee[Employee ID], Id ) )Filling empty levels with the parent's name avoids blank rows in the matrix. Create a hierarchy Level 1, Level 2, Level 3 and put it on the rows.
To hide the repeated names when someone drills below their own level, blank the measure where the row is deeper than the person:
Revenue (hierarchy) =
VAR RowDepth = ISINSCOPE ( Employee[Level 1] ) + ISINSCOPE ( Employee[Level 2] ) + ISINSCOPE ( Employee[Level 3] )
VAR MaxDepth = MAX ( Employee[Depth] )
RETURN IF ( RowDepth <= MaxDepth, [Revenue] )How are they used for security?
A role filter that lets a manager see everyone under them:
PATHCONTAINS (
Employee[Path],
LOOKUPVALUE ( Employee[Employee ID], Employee[Email], USERPRINCIPALNAME ( ) )
)Details in dynamic row-level security.
What goes wrong?
- Circular parents. An item that is its own ancestor makes
PATHfail; fix the data. - Missing parents. A parent ID that does not exist in the table errors; clean or point it to a root.
- Text paths.
PATHITEMreturns text by default; passINTEGERto compare with numeric IDs. - Calculated columns only.
PATHworks on the whole table at refresh; it is not a measure function. - Very deep trees. One column per level; decide a maximum depth.
Where can you check this?
- Microsoft Learn: Understanding functions for parent-child hierarchies in DAX
- Microsoft Learn: PATH function (DAX)
- Microsoft Learn: PATHITEM function (DAX)
Where do you start?
Add Path, Depth and three Level columns to your employee or account table and build the hierarchy. ISINSCOPE explains the depth test.