By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
For engineers who need to model org charts, bill-of-materials, or nested categories in Power BI—without the theory.
You’re handed a dataset of employees with a ManagerID column. Your boss wants a drillable org chart in Power BI—click a CEO, see their direct reports, click those, see their reports, and so on. Or maybe you’re modeling a bill of materials (BOM) where a product contains sub-assemblies, which contain parts, which contain raw materials.
ManagerID
Parent-child hierarchies let you represent these nested relationships in a single table (no star schema needed). The PATH functions (PATH, PATHITEM, PATHLENGTH, etc.) are your Swiss Army knife for traversing, flattening, and analyzing these hierarchies.
PATH
PATHITEM
PATHLENGTH
PATH(EmployeeID, ManagerID)
"CEO|VP|Director|Manager"
PATHITEM(PATH(EmployeeID, ManagerID), 2)
"VP"
Level1 = PATHITEM(PATH(...), 1)
PATHLENGTH(PATH(EmployeeID, ManagerID))
4
PATHCONTAINS(PATH(EmployeeID, ManagerID), "VP")
TRUE
LOOKUPVALUE(Employee[Name], Employee[EmployeeID], PATHITEM(PATH(...), 2))
Level1
Level2
Level3
EmployeeID
Name
Salary
Headcount
dax Path = PATH(Employee[EmployeeID], Employee[ManagerID])
Path
"123"
"123|456"
dax Level1 = PATHITEM(Employee[Path], 1) Level2 = PATHITEM(Employee[Path], 2) Level3 = PATHITEM(Employee[Path], 3) Level4 = PATHITEM(Employee[Path], 4) Level5 = PATHITEM(Employee[Path], 5)
LOOKUPVALUE
dax Level1_Name = LOOKUPVALUE(Employee[Name], Employee[EmployeeID], [Level1]) Level2_Name = LOOKUPVALUE(Employee[Name], Employee[EmployeeID], [Level2])
Employee
Org Hierarchy
Level1_Name
Level2_Name
Level3_Name
dax Headcount = VAR CurrentPath = SELECTEDVALUE(Employee[Path]) RETURN COUNTROWS( FILTER( Employee, PATHCONTAINS(Employee[Path], CurrentPath) ) )
PATHCONTAINS
dax [EmployeeID] = USERNAME() || PATHCONTAINS(Employee[Path], USERNAME())
dax HasCycle = VAR CurrentPath = Employee[Path] VAR PathLength = PATHLENGTH(CurrentPath) RETURN IF( PATHLENGTH(PATHITEM(CurrentPath, PathLength)) > 1, "CYCLE DETECTED", "OK" )
H_
H_Level1
dax MaxHierarchyDepth = MAX(Employee[PathLength])
ManagerID = BLANK()
ManagerID = EmployeeID
HasCycle
IF(ISBLANK(...), BLANK(), ...)
PATH()
PATHITEM()
❌ PATHLENGTH() (returns count)
PATHLENGTH()
"How do you extract the 3rd level of a hierarchy?"
PATHITEM(PATH(EmployeeID, ManagerID), 3)
❌ PATHLENGTH(PATH(...), 3) (returns count, not item)
PATHLENGTH(PATH(...), 3)
"You need to count all employees under a manager. Which function?"
PATHCONTAINS()
"1|2|3"
"2"
3
"3"
"You have a parent-child table with 50,000 rows. The report is slow. What’s the best optimization?"- ✅ Pre-flatten the hierarchy in Power Query or SQL.- ❌ Use LOOKUPVALUE in measures (slow).- ❌ Hardcode 10 levels in DAX (brittle).
Task: You have an employee table with EmployeeID, ManagerID, and Name. Write a DAX measure to count all direct and indirect reports for the selected employee.
Solution:
DirectAndIndirectReports = VAR CurrentPath = SELECTEDVALUE(Employee[Path]) RETURN COUNTROWS( FILTER( Employee, PATHCONTAINS(Employee[Path], CurrentPath) && Employee[EmployeeID] <> SELECTEDVALUE(Employee[EmployeeID]) ) )
Why it works:- PATHCONTAINS checks if an employee’s Path includes the selected employee’s Path.- The && excludes the selected employee themselves.
&&
PATH(KeyColumn, ParentColumn)
PATHITEM(PathColumn, Position)
PATHITEM(Path, 2)
PATHLENGTH(PathColumn)
PATHLENGTH(Path)
PATHCONTAINS(PathColumn, ID)
PATHCONTAINS(Path, "2")
TRUE/FALSE
LOOKUPVALUE(ResultColumn, SearchColumn, SearchValue)
LOOKUPVALUE(Name, EmployeeID, PATHITEM(Path, 2))
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.