Is there a way to Merge tables from the same query

sara121

New Member
Joined
Jul 7, 2022
Messages
23
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

In the same query, I transformed two tables, how do I merge these two tables into one?
The MERGE function I saw is to merge tables from two queries.

Can someone shed some light?

Thank you!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Absolutely! Just select the same query:
1676914879628.png

The sample above also illustrates using two columns as keys.
 
Upvote 0
Thanks. jdellasala!

I may not be clear about my original question as I'm still new to the power query.

In the same query, I transformed a data set in a step #"Create_DEBIT" (In this table, it has Debit and Date) and subsequently I created another step #"Create_CREDIT" (in this table, it has Credit and Date)

I'd like to merge the two into one table. and I wonder how I can do it within the query.


 
Upvote 0
Thanks. jdellasala!

I may not be clear about my original question as I'm still new to the power query.

In the same query, I transformed a data set in a step #"Create_DEBIT" (In this table, it has Debit and Date) and subsequently I created another step #"Create_CREDIT" (in this table, it has Credit and Date)

I'd like to merge the two into one table. and I wonder how I can do it within the query.


The easy way is to just duplicate the query and make one query Debit, and the other Credit and then merge them.
If you're into manually altering the M Code, when you Merge the query with itself, the code will look like this:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Debit = Table.SelectColumns(Source,{"Column1", "Column2"}),
    Credit = Table.SelectColumns(Source,{"Column3", "Column4"}),
    MergedSelf = Table.NestedJoin(Credit, {"Column3"}, Credit, {"Column3"}, "Credit", JoinKind.LeftOuter)
in
    MergedSelf
Modify the Merged Self line to merge with the Debit Table, Column1:
Power Query:
    MergedCrditDebit = Table.NestedJoin(Credit, {"Column3"}, Debit, {"Column1"}, "Credit", JoinKind.LeftOuter)
When I first tried it, I just changed the name of the second table from "Credit" to "Debit" but forgot to change the key column name which needed to be a valid column in the Debit table - either Column1 or Column2.
 
Upvote 0

Forum statistics

Threads
1,223,370
Messages
6,171,686
Members
452,418
Latest member
kennettz

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