Power Query Columns

bbrancotronex

New Member
Joined
Jun 19, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have the following data

Table1
INV_NUM INV_DTE
12345 01/02/23
23456 01/10/23
23455 01/13/23

Table 2
INV_NUM TYPE AMOUNT
12345 1 10.00
12345 3 20.00
23456 1 15.00
23456 4 20.00

Results
INV_NUM INV_DTE VALUETYPE1 VALUETYPE3 VALUETYPE4

12345 01/02/23 10.00
12345 01/02/23 20.00
23456 01/10/23 15.00
23456 01/10/23 20.00
23455 01/13/23

Can this be done in Power Query? Basically I n
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Merge queries on the INV_NUM with a left outer join. Then expand the table column
 
Upvote 0
Merge queries on the INV_NUM with a left outer join. Then expand the table column
That will show me the fields in table 2, but I dont see how it would put it in columns based on the type column?
 
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Source_two = Table.TransformColumnTypes(Excel.CurrentWorkbook(){[Name="Table2"]}[Content],{{"type", type text}}),
    merge = Table.NestedJoin(Source, {"num"}, Source_two, {"num"}, "Table2", JoinKind.LeftOuter),
    exp = Table.ExpandTableColumn(merge, "Table2", {"type", "amount"}, {"type", "amount"}),
    dup = Table.DuplicateColumn(exp, "num", "numm"),
    piv = Table.Pivot(dup, List.Sort(List.Distinct(dup[#"type"])), "type", "numm", List.Count),
    out = Table.TransformColumnNames( piv, (x)=>  if List.Contains({1..9}, try Number.FromText(x) otherwise x) then "VALUETYPE" & x else x)
in
    out


Book1
ABCDEFGHIJ
1numtestnumtypeamount
21a1910
32b1520
43c2615
52120
62425
7355
83710
9
10
11
12
13numtestamountVALUETYPE1VALUETYPE4VALUETYPE5VALUETYPE6VALUETYPE7VALUETYPE9
141a10000001
151a20001000
162b15000100
172b20100000
182b25010000
193c5001000
203c10000010
21
Sheet1
 
Upvote 0
This is a better example of what I need for the input and output
This is a better example of the input and output I need
INPUT
Inv #INV DteCategory CodeCategoryAmt
1234
2/1/2023​
1​
Freight$ 30.00
1234
2/1/2023​
2​
Processing Fee$ 25.00
1234
2/1/2023​
3​
Credit Card$ 15.00
2345
2/3/2023​
1​
Freight$ 6.00
2345
2/3/2023​
2​
Processing Fee$ 12.00
2345
2/3/2023​
4​
Handling$ 16.00
Output
Inv #INV DteCategory 1Category 2Category 3Category 4
1234
2/1/2023​
$ 30.00$ 25.00$ 15.00
2345
2/3/2023​
$ 6.00$ 12.00$ 16.00
 
Upvote 0
In that case it's easier. You should pivot on Amount. Based on my previous example

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Source_two = Table.TransformColumnTypes(Excel.CurrentWorkbook(){[Name="Table2"]}[Content],{{"type", type text}}),
    merge = Table.NestedJoin(Source, {"num"}, Source_two, {"num"}, "Table2", JoinKind.LeftOuter),
    exp = Table.ExpandTableColumn(merge, "Table2", {"type", "amount"}, {"type", "amount"}),
    piv = Table.Pivot(exp, List.Sort(List.Distinct(exp[#"type"])), "type", "amount", List.Sum),
    out = Table.TransformColumnNames( piv, (x)=>  if List.Contains({1..9}, try Number.FromText(x) otherwise x) then "VALUETYPE" & x else x)
in
    out
 
Upvote 0
create two tables named as table1 and table2
Then open a blank query via get data. Go to the advanced editor and paste the code
 
Upvote 0

Forum statistics

Threads
1,224,884
Messages
6,181,552
Members
453,052
Latest member
ezzat

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