Parent-Child Hierarchies
Parent-Child Hierarchies in DAX: PATH, PATHITEM & Organizational Trees
In organizational management, employee reporting structures, and general ledger chart of accounts, data is frequently organized in Parent-Child Hierarchies:
- An employee reports to a Manager.
- That Manager reports to a Director.
- The Director reports to a Vice President.
- The Vice President reports to the CEO.
Unlike fixed-depth product hierarchies (Category $\to$ SubCategory $\to$ Product), parent-child hierarchies have uneven and variable depth (one branch may have 3 levels, while another has 7 levels).
1. The DAX PATH Functions
DAX provides specialized functions to unravel recursive parent-child structures into linear, navigable dimensions:
| Function | Purpose | Syntax |
|---|---|---|
PATH | Generates a delimited text string tracing the lineage from top root to current node. | PATH(IDColumn, ParentIDColumn) |
PATHLENGTH | Returns the depth (level count) of the current node in the hierarchy tree. | PATHLENGTH(PathColumn) |
PATHITEM | Extracts the specific ancestor ID at a designated level of the path. | PATHITEM(PathColumn, Position, [Type]) |
PATHCONTAINS | Checks whether a specific ancestor ID exists anywhere within the path (ideal for security!). | PATHCONTAINS(PathColumn, ManagerID) |
2. Step-by-Step Parent-Child Flattening
Consider Dim_Employee with EmployeeID and ManagerID:
Step 1: Create the Hierarchy Path Column
Step 2: Extract Leveled Hierarchy Columns
Now you can drag Level_1_Executive, Level_2_VP, and Level_3_Director into a standard Matrix visual to render a clean, drillable organizational tree!
Multiple Choice Questions
PATH function use internally to separate ancestor IDs?Level 1, Level 2, Level 3) necessary for Power BI visuals?Row-Level Security (Advanced)
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Advanced Time Intelligence | Row-Level Security (Advanced) |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.