Unstack data in power query

Excel202201

New Member
Joined
Aug 31, 2022
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
I am new to Power Query, and trying to transform the following data to table. Watched few Youtube which only has one column in the example, but this one has three columns. How do I do it, I add the index column, Modulo column, then what's next? Help please

Customer #CityState
75​
TorontoON
Loan #Loan RateLoan Balance
25​
2.10%​
121,876
Approved DateMaturity DateBranch Code
2017-01-01​
2017-04-01​
12967​
Customer #CityState
76​
MississaugaON
Loan #Loan RateLoan Balance
26​
2.20%​
112,701
Approved DateMaturity DateBranch Code
2017-01-06​
2017-04-06​
12710​
Customer #CityState
77​
OttawaON
Loan #Loan RateLoan Balance
27​
2.75%​
114,390
Approved DateMaturity DateBranch Code
2017-01-11​
2017-04-11​
11809​
Customer #CityState
78​
HamiltonON
Loan #Loan RateLoan Balance
28​
2.10%​
61,597
Approved DateMaturity DateBranch Code
2017-01-16​
2017-04-16​
13735​
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    hdrs = List.Accumulate({0,2,4}, {}, (s,c)=> s & {Record.ToList(Source{c})}),
    tcn = List.Combine(hdrs),
    tbl = Table.SelectRows(Source, each not List.Contains(hdrs, Record.ToList(_))),
    tbl1 = Table.AddIndexColumn(tbl, "Index", 0, 1, Int64.Type),
    tbl2 = Table.TransformColumns(tbl1, {{"Index", each Number.IntegerDivide(_ +.5,3)}}),
    tbl3 = Table.Group(tbl2, {"Index"}, {{"All", each Table.FromRows({List.Combine(Table.ToRows(Table.SelectColumns(_, {"Column1","Column2", "Column3"})))}, tcn)}}),
    tbl4 = Table.RemoveColumns(tbl3,{"Index"}),
    Result = Table.ExpandTableColumn(tbl4, "All", tcn)
in
    Result

PQ Unstack1.xlsm
ABCDEFGHIJKLMN
1Column1Column2Column3Customer #CityStateLoan #Loan RateLoan BalanceApproved DateMaturity DateBranch Code
2Customer #CityState75TorontoON252.10%1218762017-01-012017-04-0112967
375TorontoON76MississaugaON262.20%1127012017-01-062017-04-0612710
4Loan #Loan RateLoan Balance77OttawaON272.75%1143902017-01-112017-04-1111809
5252.10%12187678HamiltonON282.10%615972017-01-162017-04-1613735
6Approved DateMaturity DateBranch Code
72017-01-012017-04-0112967
8Customer #CityState
976MississaugaON
10Loan #Loan RateLoan Balance
11262.20%112701
12Approved DateMaturity DateBranch Code
132017-01-062017-04-0612710
14Customer #CityState
1577OttawaON
16Loan #Loan RateLoan Balance
17272.75%114390
18Approved DateMaturity DateBranch Code
192017-01-112017-04-1111809
20Customer #CityState
2178HamiltonON
22Loan #Loan RateLoan Balance
23282.10%61597
24Approved DateMaturity DateBranch Code
252017-01-162017-04-1613735
26
Sheet2
 
Upvote 0
Thank you so much! Do you have another way to do it? the requirement I have is to use Index, Modulo Column and if statement.
 
Upvote 0

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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