Home » DAX » DAX Parent & Child – PATHITEM Function

DAX Parent & Child – PATHITEM Function

PATHITEM DAX Function in Power BI

PATHITEM DAX function returns the item at the specified position from a string resulting from evaluation of a PATH function. Positions are counted from left to right and it comes under Parent and child functions.

Refer similar post:- PATH DAX, PATHCONTAINS DAXPATHLENGTH DAX

Syntax:

PATHITEM(<path>, <position>, <type>)




Description:

1 path A text string in the form of the results of a PATH function.
2 position An integer expression with the position of the item to be returned.
3 type (Optional)An enumeration that defines the data type of the result:
0-Results are returned with the data type text. (default).
1- Results are returned as integers.

Note:

  • This function can be used to return a specific level from a hierarchy returned by a PATH function.
  • This function does not support the Direct Query mode.

So let’s start with an example, sample dataset format as below:

Table Name – EmployeeData

EmpId Dept EmpName Parent Id
1 Manager Sandeep Raturi
2 Team Lead Antonio Moreno 1
3 Team Lead Aria Cruz 1
4 Team Lead Dinesh Raturi 1
5 Developer Matt 4
6 Developer Jhon 4
7 Developer Jacobs 2
8 Developer David 3
9 IT Support Jack 2

In above dataset we have EmpId, Dept, EmpName & Parent Id columns, and Parent Id column contains Employee manager Id.



Follow these steps-

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 PATHITEM and write below DAX code.

PathItems(Level-2 Emp)= PATHITEM(PATH(EmployeeData[EmpId],
EmployeeData[Parent Id]),2,1)

See the output:

PATHITEM DAX

PATHITEM DAX

You can see in above screenshot, we have provided second position to fetch employee manager that are at level 2.

If you want to see level 3 positions –

PathItems(Level-3 Emp) = PATHITEM(PATH(EmployeeData[EmpId],
EmployeeData[Parent Id]),3,1)




See the final output-

PATHITEM DAX Level-3

PATHITEM DAX Level-3

Refer this- How to get manager name from specified path?

Refer similar post:- PATH DAX, PATHCONTAINS DAXPATHLENGTH DAX

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.

Leave a Reply