Power Query sum two columns from different tables

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,834
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have loaded two sales data tables into the PQ editor.

Each table only contains a single column of data.

One is called April and the other May.

All I want is to create a new table containing a single column called Total, which sums each row within the two tables.

How can this be achieved?

Thanks
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
If the rows have some matching component e.g. and ID then merge and SUm , if they don't add an index column to both table and merge using the Index as the ID, then sum columns as needed
 
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"May", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Merged Queries" = Table.NestedJoin(#"Added Index", {"Index"}, Table1, {"Index"}, "Table1", JoinKind.LeftOuter),
    #"Expanded Table1" = Table.ExpandTableColumn(#"Merged Queries", "Table1", {"April", "Index"}, {"Table1.April", "Table1.Index"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Table1", "SUM", each [May]+[Table1.April]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Table1.Index", "Index", "Table1.April", "May"})
in
    #"Removed Columns"
Book1
ABC
1AprilMay
214
325
436
Sheet1
Book1
A
1SUM
25
37
49
SUM
 
Upvote 0
If the rows have some matching component e.g. and ID then merge and SUm , if they don't add an index column to both table and merge using the Index as the ID, then sum columns as needed
I'm afraid I not sure what you mean.

This is what I have:

1687357705772.png


The OK button is greyed out.
 
Upvote 0
Paste the code above into advanced editor and you can see the applied steps
Looking at the above you will need to add Index Column to bothe tables like below
1687358569048.png

When you Merge then use the Index Column to keep the rows aligned that you want to sum(you need to select the column ) then you will be able to click on OK

1687358609300.png
 
Upvote 0
Ok if you are using the code you do not need to add the index columns manually as the code has that in it.
I was explaining how to add the index column as it looked like you wanted to do it manually yourself. the error is showing because it now sees additional column added.
 
Upvote 0
Here is file example
Example
Thanks, have just downloaded your example.

However, my two tables, April and May are located on different worksheets within the same workbook.

Does that change things or will it work equally well?
 
Upvote 0

Forum statistics

Threads
1,215,129
Messages
6,123,216
Members
449,091
Latest member
jeremy_bp001

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top