The PATHLENGTH function returns the number of parents of the corresponding item, including itself.
PATHLENGTH(
path
)
- path: Text string resulting from applying the PATH function.
The PATHLENGTH function returns an integer.
The returned result includes the item itself referenced by the path.
We start from the following table:
This table contains worker identifiers and the hierarchical relationship between them. The scheme of this hierarchy is shown in the following figure:
Once the path of each employee is obtained, we can extract the number of superiors of each worker (including himself) with the following measure:
pathlength = PATHLENGTH(Employees[path])
We can confirm how worker 112 -located at the top of the hierarchy- has a path of length 1 (only him), while workers 117, 221 and 81, for example, have a path of length 5 (the maximum in the structure).