Merging two queries in Power Query: find "M00123" using lookup value of "123"

danhendo888

Board Regular
Joined
Jul 15, 2019
Messages
142
Office Version
  1. 365
Platform
  1. Windows
I have a table in Sheet1 (query1) which has vendor numbers and invoice numbers
Sheet2 (query2) is the data table and has vendor numbers, invoice numbers, amount, paid dates

I want to load both as a query and merge them
I would do 'group by' for the Sheet1 table using the first two columns to show unique values
For Sheet2, I would 'group by' vendor, invoice number, amount

Suppose I want to lookup 123 in query1 and find invoice M00123 in query2
How do I merge the queries and have M00123's invoice amount and paid date show up for 123?

https://1drv.ms/x/s!AvjBsEPEq12ngTcWgQnwXMZmJm_2?e=HQJC3s
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
maybe
Code:
[SIZE=1]let
    Source1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Source2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    Merge = Table.TransformColumnTypes(Table.ExpandTableColumn(Table.NestedJoin(Source1,{"Vendor"},Source2,{"Vendor"},"Source2",JoinKind.LeftOuter), "Source2", {"Amount", "Paid Date"}, {"Amount", "Paid Date"}),{{"Paid Date", type date}})
in
    Merge[/SIZE]

btw. your description does not match the example
 
Last edited:
Upvote 0
Have updated workbook in the link with Sandy's code

In the Merge query, the last Applied Step has the below code:

= Table.TransformColumnTypes(Table.ExpandTableColumn(Table.NestedJoin(Source,{"Vendor"},Source2,{"Vendor"},"Source2",JoinKind.LeftOuter), "Source2", {"Amount", "Paid Date"}, {"Amount", "Paid Date"}),{{"Paid Date", type date}})

Could someone please help me understand the functions Table.ExpandTableColumn and Table.NestedJoin, and how it manages to display the records of invoice M00123 from Query2 using lookup value of 123 from Query1
 
Upvote 0
the result of the M-code is not what you want?
I see result and your output - this is the same except date format.
 
Upvote 0
It is what I want but I'm trying to understand the functions. You combined several functions into one applied step. That's great, but as a beginner, kinda hard to learn from it and apply it/practise on other examples.
Anyway, thank you for your help, I appreciate it.
 
Upvote 0
sure, now is better?

Code:
[SIZE=1]let
    Source1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Source2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    Merge = Table.NestedJoin(Source1,{"Vendor"},Source2,{"Vendor"},"Source2",JoinKind.LeftOuter),
    Expand = Table.ExpandTableColumn(Merge, "Source2", {"Amount", "Paid Date"}, {"Amount", "Paid Date"}),
    Type = Table.TransformColumnTypes(Expand,{{"Paid Date", type date}})
in
    Type[/SIZE]
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,188
Members
448,554
Latest member
Gleisner2

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