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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
GMadd
Helper I
Helper I

Power BI Power Query Append Two table Distinct Values Only Based on two columns each row

I have two tables I need to append in excel files.

The first table called "Main" and the file name is called "Yearly Shipping". This file contains data for everything shipped year to date. 

The second table is called "MtoD" and the file name is called "Monthly Shipping".

The ERP I am using gives me a report daily that is always month to date. Meaning I will get all shipping data from August 1st through August 20th (today is August 20th). Tomorrow I will get the report and it will be from August 1st through August 21st and so on down the road. I want power query to remove duplicates based on two columns in each row. These two columns are called "Delivery" and "Material". If another row has the same delivery number and material number I do not want to add it to the table called "Main". I need to know how to write M-code to state I only want to see distinct rows and I am struggling on how to do this. Below is a sample of my "Main" table and "MtoD" table and what I want the "Main" tabl

 Main Report 
DeliveryAct. Gds Mvmnt DateMaterial
881375217/30/202423461BIO
881375227/30/202422852BIO
881375227/30/202423642BIO
8813053519-Aug-2436112CLX
8813053519-Aug-2436106CLX
8813601919-Aug-2429005CLX
8813601919-Aug-2412005CLX
8813601919-Aug-2450006ACL
8814287619-Aug-2423505PTM
8814287619-Aug-2423504PTM
8814287619-Aug-2423606PTM
   
 MtoD 
DeliveryAct. Gds Mvmnt DateMaterial
8813053519-Aug-2436112CLX
8813053519-Aug-2436106CLX
8813601919-Aug-2429005CLX
8813601919-Aug-2412005CLX
8813601919-Aug-2450006ACL
8814287619-Aug-2423505PTM
8814287619-Aug-2423504PTM
8814287619-Aug-2423606PTM
8813053519-Aug-2559232CLX
8813053519-Aug-2511022CSP
   
 End Result (Appended Table)
DeliveryAct. Gds Mvmnt DateMaterial
881375217/30/202423461BIO
881375227/30/202422852BIO
881375227/30/202423642BIO
8813053519-Aug-2436112CLX
8813053519-Aug-2436106CLX
8813601919-Aug-2429005CLX
8813601919-Aug-2412005CLX
8813601919-Aug-2450006ACL
8814287619-Aug-2423505PTM
8814287619-Aug-2423504PTM
8814287619-Aug-2423606PTM
8813053519-Aug-2559232CLX
8813053519-Aug-2511022CSP
1 ACCEPTED SOLUTION

No worries. You can change the line that is currently...

#"Appended Query" = Table.Combine({#"Changed Type", MtoD})

to

#"Appended Query" = Table.Distinct(Table.Combine({#"Changed Type", MtoD}))

The #"Changed Type" replaces the 'mainTable' in what I initially wrote while the MtoD replaces the 'mtdTable'.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

4 REPLIES 4
jgeddes
Super User
Super User

Does this work for you?

Table.Distinct(Table.Combine({mainTable, mtdTable}))

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thanks for the help! I should have said I am very new to writing these formulas; with that said where do I add this into the append formlua below?

let
Source = Excel.Workbook(File.Contents("C:\Users\gmadden\Yearly Shipping.xlsx"), null, true),
Main_Sheet = Source{[Item="Main",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Main_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Delivery", Int64.Type}, {"Plant", type text}, {"Created On", type date}, {"Act. Gds Mvmnt Date", type date}, {"Goods Issue Date", type date}, {"Name of the ship-to party", type text}, {"Location of the ship-to party", type text}, {"Region", type text}, {"Postal Code", type text}, {"Incoterms", type text}, {"Material", type text}, {"Description", type text}, {"Actual delivery qty", Int64.Type}, {"Base Unit of Measure", type text}, {"Net weight", type number}, {"Weight Unit", type text}, {"Shipping Conditions", Int64.Type}, {"Route", type text}, {"Created By", type text}, {"Reference Document", Int64.Type}, {"Total Pallets", Int64.Type}, {"Total Weight", type number}, {"Ship-To Party", Int64.Type}, {"Purchase Order Number", type text}, {"TU partner", type text}, {"Otm Shipment Number", Int64.Type}, {"Sold-To Party", Int64.Type}, {"Name of sold-to party", type text}, {"Overall pick.status", type text}, {"Overall WM status", type text}, {"Container/Trailer/PRO Number", type text}, {"Pick up Appt Date", type date}, {"Pick up Appt Time", type datetime}, {"Rush Order Flag", type text}, {"Delay Reason Code - Header", type text}, {"Profit Center", Int64.Type}, {"Net Value", type number}, {"Time Created", type datetime}, {"Carrier Assigned Date", type date}}),
#"Appended Query" = Table.Combine({#"Changed Type", MtoD})
in
#"Appended Query"

No worries. You can change the line that is currently...

#"Appended Query" = Table.Combine({#"Changed Type", MtoD})

to

#"Appended Query" = Table.Distinct(Table.Combine({#"Changed Type", MtoD}))

The #"Changed Type" replaces the 'mainTable' in what I initially wrote while the MtoD replaces the 'mtdTable'.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thank you for your help! This worked perfectly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors