Forum

Merge Two Tables To...
 
Notifications
Clear all

Merge Two Tables To Show Items That Are In Both Table

3 Posts
3 Users
0 Reactions
138 Views
(@jlandicho1)
Posts: 1
New Member
Topic starter
 

Hi,

I was trying to merge an Actuals table to a Standard table based on columns Product and Component using a Left Outer join. Below is the M code from the Advanced Editor:

let
Source = Table.NestedJoin(Actual, {"Product", "Component"}, Standard, {"Product", "Component"}, "Standard", JoinKind.LeftOuter),
#"Expanded Standard" = Table.ExpandTableColumn(Source, "Standard", {"Standard"}, {"Standard"})
in
#"Expanded Standard"

LarsAustin_0-1658983459561.png

LarsAustin_1-1658983498144.png

This is the output that I get as expected:

LarsAustin_2-1658983549582.png

But my desired output is the table below:

LarsAustin_3-1658983664566.png

I want to be able to capture one of the items in the standard that is missing from the actual. I tried using different merge types but it is not giving me the exact result i wanted.

 

I will appreciate your inputs to make this work.

 

Thank you

 

Jojemar

 
Posted : 29/07/2022 1:07 am
Riny van Eekelen
(@riny)
Posts: 1185
Member Moderator
 

Hi Jojemar,

First of all you need to do a full outer join. Then add a custom column that fills the null components in the first table with the component from the second table. Then remover the two original component columns.

The attached file demonstrates what I mean.

 
Posted : 29/07/2022 3:23 am
(@bluesky63)
Posts: 162
Estimable Member
 

Hi Jojemar

The quick way is to Append table 2 to table 1,  then Group by Product and Component,  two aggregations Actual and Standards Just Min or Max it

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"Component", type text}, {"Actual", Int64.Type}}),
#"Appended Query" = Table.Combine({#"Changed Type", Table2}),
#"Grouped Rows" = Table.Group(#"Appended Query", {"Product", "Component"}, {{"Actual", each List.Min([Actual]), type number}, {"Standard", each List.Min([Standard]), type number}})
in
#"Grouped Rows"

 

See Attached

 
Posted : 29/07/2022 3:32 am
Share: