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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
agajka
New Member

Power Query Merge - populate only first match

Hello All!

I'm looking for a way to join two tables in Power Query (source data is from SFDC: IPA_Opportunities + WorkOrder_Asset, key: Opportunity__c from Opportunity and WorkOrder objects), but only display details for the first match, considering that in the first table we have duplicate Opportunities corresponding to each IPA and they can't be removed.

 

Left table:

Opportunity NameIPA
Opp1IPA-0888
Opp1IPA-0889

 

Right table:

Opportunity NameWO Number
Opp10012345

 

Standard expected behavior of left-outer merge:

Opportunity NameIPAWO Number
Opp1IPA-08880012345
Opp1IPA-08890012345

 

Searched solution:

Opportunity NameIPAWO Number
Opp1IPA-08880012345
Opp1IPA-0889null

 

Thank you for your help!

Regards,

A.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @agajka ,
You can try the following code

let
    Source1 = #"Table 1",
    Source2 = #"Table 2",
    GroupedTable = Table.Group(Source1, {"Opportunity"}, {{"AllData", each _, type table [Opportunity=nullable text, IPA=nullable text]}}),
    AddIndex = Table.TransformColumns(GroupedTable, {"AllData", each Table.AddIndexColumn(_, "Index", 1, 1, Int64.Type)}),
    #"Expanded AllData" = Table.ExpandTableColumn(AddIndex, "AllData", {"Index"}, {"Index"}),
    MergedTables = Table.NestedJoin(#"Expanded AllData", {"Opportunity"}, Source2, {"Opportunity"}, "Table2", JoinKind.LeftOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(MergedTables, "Table2", {"Number"}, {"Table2.Number"}),
    AddCustom = Table.AddColumn(#"Expanded Table2", "Number", each if [Index] = 1 then [Table2.Number] else null),
    #"Removed Columns" = Table.RemoveColumns(AddCustom,{"Index", "Table2.Number"})
in
    #"Removed Columns"

Final output

vheqmsft_0-1729651843238.png

 

Best regards,
Albert He


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @agajka ,
You can try the following code

let
    Source1 = #"Table 1",
    Source2 = #"Table 2",
    GroupedTable = Table.Group(Source1, {"Opportunity"}, {{"AllData", each _, type table [Opportunity=nullable text, IPA=nullable text]}}),
    AddIndex = Table.TransformColumns(GroupedTable, {"AllData", each Table.AddIndexColumn(_, "Index", 1, 1, Int64.Type)}),
    #"Expanded AllData" = Table.ExpandTableColumn(AddIndex, "AllData", {"Index"}, {"Index"}),
    MergedTables = Table.NestedJoin(#"Expanded AllData", {"Opportunity"}, Source2, {"Opportunity"}, "Table2", JoinKind.LeftOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(MergedTables, "Table2", {"Number"}, {"Table2.Number"}),
    AddCustom = Table.AddColumn(#"Expanded Table2", "Number", each if [Index] = 1 then [Table2.Number] else null),
    #"Removed Columns" = Table.RemoveColumns(AddCustom,{"Index", "Table2.Number"})
in
    #"Removed Columns"

Final output

vheqmsft_0-1729651843238.png

 

Best regards,
Albert He


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

Omid_Motamedise
Super User
Super User

Group the data on the left table based on first column and also use all row operation, then make the merge and after that create an we column based on the values match 

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors