How to use PQ to expand items in one specific column into separate columns

ubergreen

New Member
Joined
Jun 13, 2024
Messages
33
Office Version
  1. 2021
I have values in column B that I want to expand out into their own individual columns but all be on the same row. The only solutions that I have found so far ends up affecting all of the other rows/columns during the process, so I haven't been able to find a solution that can allow me to apply this action to only one specific column in my worksheet.

First image is how the original data looks.
1.jpg


Second image is how I want it to look afterwards.
2.jpg
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    func = (tbl) => 
        [cols = Table.ToColumns(tbl),
        cols_updated = 
            {cols{0}} & 
            List.Transform(List.RemoveNulls(cols{1}), (x) => {null, x}) & 
            List.Skip(cols, 2),
        res = Table.FromColumns(cols_updated)][res],
    group = Table.Group(
        Source, 
        "Column1",
        {"x", func}, 
        GroupKind.Local, 
        (s, c) => Number.From(c <> null)
    ),
    z = Table.Combine(group[x])
in
    z
 
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    func = (tbl) =>
        [cols = Table.ToColumns(tbl),
        cols_updated =
            {cols{0}} &
            List.Transform(List.RemoveNulls(cols{1}), (x) => {null, x}) &
            List.Skip(cols, 2),
        res = Table.FromColumns(cols_updated)][res],
    group = Table.Group(
        Source,
        "Column1",
        {"x", func},
        GroupKind.Local,
        (s, c) => Number.From(c <> null)
    ),
    z = Table.Combine(group[x])
in
    z

Thanks for the reply. I am still fairly new to PQ. Do you think you could break down what is happening with each line so that I can understand it better and be able to apply it?

Simply copy/pasting it into my workbook isn't working, but it is probably because I am missing some sort of basic concept to implement it correctly, such as table or workbook naming variances.
 
Upvote 0
@ubergreen , in short, we group data by non-null values in column A and replace column B with several columns of {null, column_B_value} combinations.
In Excel select all data, press Ctrl-T to create table (uncheck "my data has headers" option), make sure that table name is Table1 and load this table into PQ. In Advanced Editor replace all code that loads your table with mine.
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
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