Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
witbi
Helper I
Helper I

PATH function extract sub-level 2 hierarchy

I'm trying to use PATH functions to generate a flat table for filtering. Examples online seem to start with an explicit hierarchy in the table. I'm stuck on extracting the sub-level 2 hierarchy from my data (see below). Am starting out with Power BI so if anyone can provide some guidance that would be great.

 

Thanks in advance


witbi_0-1611086265926.png

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hello @witbi 
Are you looking for this?
Yes, try this. For this, you need to add the index column.
You can easily add the index column in the power query editor.

Capture2.PNG

View solution in original post

wdx223_Daniel
Super User
Super User

@witbi here is the formula for your reference

you just need to change the number which the arrow points.

wdx223_Daniel_0-1611188980818.png

 

View solution in original post

6 REPLIES 6
wdx223_Daniel
Super User
Super User

@witbi here is the formula for your reference

you just need to change the number which the arrow points.

wdx223_Daniel_0-1611188980818.png

 

Wow, many thanks again @wdx223_Daniel. This works! I have learned much from your clear and elegant solutions.

Anonymous
Not applicable

Hello @witbi 
Are you looking for this?
Yes, try this. For this, you need to add the index column.
You can easily add the index column in the power query editor.

Capture2.PNG

Yes @Anonymous an Index makes sense

lbendlin
Super User
Super User

LOOKUPVALUE is most likely not what you want. Please provide sample data in usable format (not a picture) and show the expected outcome.

Hi Ibendlin,

Column 1-4 is the initial table. As @Anonymous  pointed out I was missing the index.

"Expected Hierarchy" is what I am looking to calculate so I can run PATH functions like this to calculate Level 1, Level 2, Level for use in a slicer:

Level 1= LOOKUPVALUE(Expected_result[Description],Expected_result[Index], PATHITEM(Expected_result[Path],1,1))

 

However, I've tried to calculate the column "Calculated Hierarchy" to resemble the "Expected Hierarchy" but it has become overly complicated. I would appreciate any ideas on creating a calculated column.

 

Calculated Hierarchy =
VAR _l1=IF(LEN(Expected_result_test[Ref])=Expected_result_test[Pathlength],Expected_result_test[Index])
VAR _delimiter1=SUBSTITUTE(Expected_result_test[Ref],".","|",1)
VAR _l2_len=SEARCH("|",_delimiter1,,LEN(_delimiter1))-1
VAR _parent=LEFT(_delimiter1,_l2_len)
VAR _index= IF(ISERROR(LOOKUPVALUE(Expected_result_test[Index],Expected_result_test[Ref],_parent)),"",LOOKUPVALUE(Expected_result_test[Index],Expected_result_test[Ref],_parent))
VAR _path=
IF(
ISBLANK(_l1),
CONCATENATE(_index,CONCATENATE("|",Expected_result_test[Index])),
_l1
)
RETURN
_path


Sample data:

Ref,Description,Event,Index,Expected Hierarchy,Level 1,Level 2,Level 3,Calculated Hierarchy
1,Andy,A,1,1,Andy,,,1
1.1,Green,A,2,1|2,Andy,Green,,|1
1.2,Blue,A,3,1|3,Andy,Blue,,|3
1.2.1,Water,A,4,1|3|4,Andy,Blue,Water,|4
2,Bill,A,5,5,Bill,,,5
2.1,Yellow,A,6,5|6,Bill,Yellow,,5|6
2.1.1,Wood,A,7,5|6|7,Bill,Yellow,Wood,5|7
2.1.2,Paper,A,8,5|6|8,Bill,Yellow,Paper,5|8
2.2,Orange,A,9,5|9,Bill,Orange,,5|9
3,Chris,B,10,10,Chris,,,10
3.1,Purple,B,11,10|11,Chris,Purple,,|11
4,Dave,B,12,12,Dave,,,12
4.1,Black,B,13,12|13,Dave,Black,,12|13
4.2,White,B,14,12|14,Dave,White,,12|14
1,Andy,C,15,1,Andy,,,15
1.2,Blue,C,16,1|3,Andy,Blue,,|16
1.2.1,Water,C,17,1|3|4,Andy,Blue,Water,|17
3,Chris,C,18,10,Chris,,,18
3.1,Purple,C,19,10|11,Chris,Purple,,19

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.