Power Query - split rows of data from multiple columns into rows with respective value on a separate line

katsdelite

New Member
Joined
May 15, 2005
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm new to Power Query and have tried to create this but I keep getting so far and get stuck. I have an excel spreadsheet that has data listed by employee number in column A, with columns of data for each employee. I want to transform that data and parse it out to have one line for each employee with their own data under the respective column.

Thanks in advance!

Original
1731193651432.png


Desired
1731193676783.png
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Power Query:
let
    ladder = (lst) => ((first) => List.Transform({1..List.Count(lst) - 1}, (i) => {first} & List.Repeat({null}, i - 1) & {lst{i}}))(List.First(lst)),
    Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
    to_list = Table.ToList(Source, ladder),
    to_table = Table.FromList(List.Combine(to_list), (x) => x, Value.Type(Source))
in
    to_table
 
Upvote 0
Solution
v2
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    to_list = Table.ToList(
        Table.UnpivotOtherColumns(Source, {"Employee Number"}, "a", "b"),
        (x) => Record.FromList({x{0}, x{2}}, {"Employee Number", x{1}})
    ), 
    tbl = Table.FromRecords(to_list, Value.Type(Source), MissingField.UseNull)
in
    tbl
 
Upvote 0
Thank you, thank you, thank you! I've spent days trying to figure out how to do it and you spit it out like it's nothing lol

How can I have it delete empty lines in PQ - or is it best to do that in the output?
 
Upvote 0
I figured it out and it works beautifully! Thanks again, I really appreciate it!
 
Upvote 0

Forum statistics

Threads
1,224,454
Messages
6,178,766
Members
452,875
Latest member
Disastrouscoder

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