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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
sglendenning
Helper II
Helper II

Subtract multiple columns from two tables

I have two tables organized by MMYYYY and sales rep with the exact same data columns for attempts, contacts, sales (and 20 other data columns) but need to subtract the same columns from one table to the other.  I'm trying to use power query but am stumped as to the best solution.

1 ACCEPTED SOLUTION

Hi @sglendenning ,

 

Check this file: Download PBIX 

 

Capture.PNG



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

Proud to be a Super User!



View solution in original post

7 REPLIES 7
Greg_Deckler
Community Champion
Community Champion

Would Appending the tables help?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
camargos88
Community Champion
Community Champion

@sglendenning ,

 

Can you give some example with dummy data ?



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

Proud to be a Super User!



Table1

DateSalesRepAttemptsContactsSales
202004Joe100105
202004Sue1502010
202003Joe200202
202003Sue503020

 

Table2

DateSalesRepAttemptsContactsSales
202004Joe1051
202004Sue511
202003Joe2052
202003Sue410
     

 

I need to subtract Table1 from Table2 by date and SalesRep.  So output would be;

DateSalesRepAttemptsContactsSales
202004Joe9054
202004Sue145199
202003Joe180150
202003Sue462920

// QueryOut
let
    Source = Table1&Table2,
    funcLists = List.Transform(List.Skip(Table.ColumnNames(Source),2),each {_,(x)=>let lst=Table.Column(x,_) in lst{0}-lst{1}}),
    result = Table.Group(Source,{"Date","SalesRep"},funcLists)    
in
    result

Check my file:  Subtract multiple columns from two tables.pbix 

 

If my code solves your problem, mark it as a solution

Hi @sglendenning ,

 

Check this file: Download PBIX 

 

Capture.PNG



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

Proud to be a Super User!



Thank you, I'm new to Power Query so much appreciated.  What does the {0} do at the end of the formula?  Can I ask how you would write within the formula if there is no value for the rep in Table2 how you would return the value in Table1?

Hi, @sglendenning 

I merged the two tables directly and then grouped them, "{0},  {1}" being the table1 and the table2 corresponding to the values in each column. I didn't consider that rep in Table2 has no value. You can simulate the new data. Let me see how to realize it.

 

My text is machine translated, I wonder if the translation can make you understand my meaning

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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 Solution Authors