Power BI hierarchy

Posted by John Liu on Thursday, February 23, 2023

In Power BI, you can create new hierarchy in Model View. There are simply one-level hierarchy, such as category and subcategory for product. A more complex one is the multi-level parent-child hierarchy, such as orgnisation management chart which has multiple levels.

For the complex parent-child hierarchy, Power BI does not flatten the hierarchy by default and this needs to be done manually using PATH() AND PATHITEM() functions.

//create a new column, Path
//The PATH() function returns a string contains a delimited list of IDs, starting with the top/root of a hierarchy and ending with the specified ID.
Path = PATH(Employee[Employee ID], Employee[Manager ID])

//create each level based on the above Path
//The PATHITEM() function returns the nth item in the delimited list produced by the Path() function
Level 1 = PATHITEM(Employee[Path],1)
Level 2 = PATHITEM(Employee[Path],2)
Level 3 = PATHITEM(Employee[Path],3)

//then create hierarchy using the Level columns above

For more details, see Microsoft Learn