PATHLENGTH DAX function is used to counts the number of parents to the specified item in a given PATH result, including self.
This function is categorized under the Parent and child function.
|1||path||A text expression resulting from evaluation of a PATH function.|
This function does not support Direct Query mode.
So let’s start with an example, sample dataset format as below:
Table Name – EmployeeData
|2||Team Lead||Antonio Moreno||1|
|3||Team Lead||Aria Cruz||1|
|4||Team Lead||Dinesh Raturi||1|
In above dataset we have EmpId, Dept, EmpName & Parent Id columns, and Parent Id column contains Employee manager Id.
Follow these steps in order to counts the number of parents(levels) to the specified item in a given PATH-
Step-1: Create a new calculated column for PATH and write below DAX code.
Path = PATH(EmployeeData[EmpId],EmployeeData[Parent Id])
Step-2: Create another calculated column for PATHLENGTH and write below DAX code.
PathLength - Levels = PATHLENGTH(PATH(EmployeeData[EmpId],EmployeeData[Parent Id]))
See the output
Hope you enjoyed the post. Your valuable feedback, question, or comments about this post are always welcome or you can leave us message on our Contact form , we will revert to you asap.