cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Remco
Frequent Visitor

Left join that on match the first record of the right tabl

Hi, 

I'm looking for a way to join 2 table in Power Query. This should be a left join that only returns the first record of the right table. See my example below:

Left_join.png

1 ACCEPTED SOLUTION

Accepted Solutions
Super User III
Super User III

Re: Left join that on match the first record of the right tabl

Yes, you can use the "Aggregate"-tab instead of the "Expand"-tab, choose any of the defualt actions and replace the function by "List.First".

 

Table.AggregateTableColumn(#"Grouped Rows", "Count", {{"Case", List.Count, "Count of Case"}})

will become

Table.AggregateTableColumn(#"Grouped Rows", "Count", {{"Case", List.First, "Count of Case"}})

 

But performance might be a pain: https://www.thebiccountant.com/2019/10/28/performance-tip-for-aggregations-after-joins-in-power-quer...

 

Better just to reference the lookup table then, do the distinct manually and uncheck "load to data model" if you're going to use that table just for this purpose.

 

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark my post as a solution. Thanks!

Imke Feldmann

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

 

View solution in original post

5 REPLIES 5
Super User III
Super User III

Re: Left join that on match the first record of the right tabl

Use Table.Distinct(#"Right table", {"TrackingID"}) in the merge (by tweaking the code) or remove duplicates with the UI before the merge.

 

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark my post as a solution. Thanks!

Imke Feldmann

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

 
Remco
Frequent Visitor

Re: Left join that on match the first record of the right tabl

That may work in my query, but I'm not sure how to apply this on the query below.

 

#"Merged Queries" = Table.NestedJoin(#"Renamed Columns", {"Shipment Number"}, BKM_UPS_D2L_carton_details_lookup, {"TrackingID"}, "BKM_UPS_D2L_carton_details_lookup", JoinKind.LeftOuter),
#"Expanded BKM_UPS_D2L_carton_details_lookup" = Table.ExpandTableColumn(#"Merged Queries", "BKM_UPS_D2L_carton_details_lookup", {"Virtual_Warehouse"}, {"BKM_UPS_D2L_carton_details_lookup.Virtual_Warehouse"}),
#"Renamed Columns2" = Table.RenameColumns(#"Expanded BKM_UPS_D2L_carton_details_lookup",{{"BKM_UPS_D2L_carton_details_lookup.Virtual_Warehouse", "Location TrackingID"}}),

Super User III
Super User III

Re: Left join that on match the first record of the right tabl

Hi @Remco 

adjust the first step like so:

 

#"Merged Queries" = Table.NestedJoin(#"Renamed Columns", {"Shipment Number"}, Table.Distinct(BKM_UPS_D2L_carton_details_lookup, {"TrackingID"), {"TrackingID"}, "BKM_UPS_D2L_carton_details_lookup", JoinKind.LeftOuter),

 

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark my post as a solution. Thanks!

Imke Feldmann

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

 
Remco
Frequent Visitor

Re: Left join that on match the first record of the right tabl

Query editor error says that it is missing a comma, but all comma's are at the right place in your query. But I also found out that my data is to 'dirty' voor Distinct. I have to dive deeper in the data of the second table.

Or is there an other solution to fetch only the first matching record of the right table?

Super User III
Super User III

Re: Left join that on match the first record of the right tabl

Yes, you can use the "Aggregate"-tab instead of the "Expand"-tab, choose any of the defualt actions and replace the function by "List.First".

 

Table.AggregateTableColumn(#"Grouped Rows", "Count", {{"Case", List.Count, "Count of Case"}})

will become

Table.AggregateTableColumn(#"Grouped Rows", "Count", {{"Case", List.First, "Count of Case"}})

 

But performance might be a pain: https://www.thebiccountant.com/2019/10/28/performance-tip-for-aggregations-after-joins-in-power-quer...

 

Better just to reference the lookup table then, do the distinct manually and uncheck "load to data model" if you're going to use that table just for this purpose.

 

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark my post as a solution. Thanks!

Imke Feldmann

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

 

View solution in original post

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Top Solution Authors
Top Kudoed Authors