Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

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

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

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

     

     

     

1 Reply

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Community Champion

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

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