Power Query--Split Multiple Columns at one time

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
8,103
Office Version
  1. 365
Platform
  1. Windows
In attached is a sample. I wish to split the columns that have been merged with the pipe delimiter. I now wish to split each of these columns. I can do this one column at a time, but I wish to do this with one line of Mcode.

Book1
ABCDEF
1Column101234
2xyz@abc.comCom1|view onlycom2|view only
3yog@abc.comCom1|view onlycom2|view onlycom3|view only
Sheet2
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi @alansidman,

you got me fooled with "I wish to do this with 1 line of M-code".

I got very quickly to the code below which seems to handle the null columns without any hassle.
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Added Custom" = Table.AddColumn(Source, "Custom", each Text.Combine(Record.ToList(Source{_}),"|"))
in
    #"Added Custom"
but then struggled to have the export done in a way that's future proof. Need to look further into the code smozgur made as he managed to do in a clean way as you said.

Nice work by @sandy666 and @billszysz too.
 
Upvote 0
@GraH

Rich (BB code):
you got me fooled with "I wish to do this with 1 line of M-code".

I guess you figured out what I meant by that. Not having to do each column individually. This has been a great learning experience. All four of you have provided me with some new insight on this particular item. Thanks again.
 
Upvote 0
my two cents with another approach
split.png

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    UOC = Table.UnpivotOtherColumns(Source, {"Column1"}, "Attribute", "Value"),
    Sort = Table.Sort(UOC,{{"Attribute", Order.Ascending}}),
    Split2Rows = Table.ExpandListColumn(Table.TransformColumns(Sort, {{"Value", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Value"),
    Index0 = Table.AddIndexColumn(Split2Rows, "Index", 0, 1),
    RC = Table.RemoveColumns(Index0,{"Attribute"}),
    Pivot = Table.Pivot(Table.TransformColumnTypes(RC, {{"Index", type text}}, "en-GB"), List.Distinct(Table.TransformColumnTypes(RC, {{"Index", type text}}, "en-GB")[Index]), "Index", "Value")
in
    Pivot
this is not "one-line" code of course :ROFLMAO:
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,840
Messages
6,121,895
Members
449,058
Latest member
Guy Boot

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