Power Query Self-Merge/Lookup Question

cr731

Well-known Member
Joined
Sep 17, 2010
Messages
611
I have a table with values such as below,

IDID DescriptionParent ID
ADescription AA
ADescription AA
BDescription BA
CDescription CB

<tbody>
</tbody>

I am trying to create a new column to show the Parent ID description. The outcome would be as shown below:

IDID DescriptionParent IDParent ID Description
ADescription AADescription A
ADescription AADescription A
BDescription BADescription A
CDescription CBDescription B

<tbody>
</tbody>


I'm struggling with how to accomplish this in Power Query. When I try to self-merge the table, I get many duplications because I have duplicate rows as shown above (where ID A is listed twice... and where ID A is the parent of ID A, meaning it is the highest level of the hierarchy).

If I self-merge this table onto itself, it results in a multiplication effect where I get four rows for A.

Is there a way to perform just a simple lookup to get the title from the ID Description title for the Parent ID? Would a Custom Column be more well suited for this?

Thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try this code.
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    ChType = Table.TransformColumnTypes(Source,{{"ID", type text}, {"ID Description", type text}, {"Parent ID", type text}}),
    RemoveDuplicates = Table.Distinct(ChType),
    SecondTable = Table.RemoveColumns(RemoveDuplicates,{"Parent ID"}),
    Merge = Table.NestedJoin(ChType,{"Parent ID"},SecondTable,{"ID"},"New Column",JoinKind.LeftOuter),
    Expand = Table.ExpandTableColumn(Merge, "New Column", {"ID Description"}, {"Parent ID Description"})
in
    Expand

Regards
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,639
Members
449,093
Latest member
Ahmad123098

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top