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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Herbie
Regular Visitor

Finding a root id using multiple nested joins - Is there a more performant option?

Hello,

 

I have a table that includes a column containing previous_ids. I want to use this column to find each record's root id. Some records don't have a previous_id and some previous_id's lead to a record that has a previous_id of its own. The longest chain is 5.

 

This is the desired outcome is this:

 

idprevious_idroot_id
1null1
2null2
311
431
522
641

 

I have solved this using a sequence of nested joins. Bascially:

= Table.NestedJoin(#"previous_step", {"previous_id_number_1"}, #"foo_step", {"id"}, "previous_id_number_2", JoinKind.LeftOuter)

= Table.NestedJoin(#"previous_step", {"previous_id_number_2"}, #"foo_step", {"id"}, "previous_id_number_3", JoinKind.LeftOuter)

...

 

This method works, but seems slow and fragile.

 

Is there a better way to do this in Power Query?

 

Thanks,

Herbie

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

the category of PATH function in DAX can resolve this kind of problems efficiently.

wdx223_Daniel_0-1662098259389.png

in M language, it may take more resources and time.

wdx223_Daniel_1-1662098568826.png

 

 

 

View solution in original post

1 REPLY 1
wdx223_Daniel
Super User
Super User

the category of PATH function in DAX can resolve this kind of problems efficiently.

wdx223_Daniel_0-1662098259389.png

in M language, it may take more resources and time.

wdx223_Daniel_1-1662098568826.png

 

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors