Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Nks_Mr
Frequent Visitor

Split multiple columns into one row

Nks_Mr_1-1732807068584.png

 


Hi Guys,

first off - sorry, I am quite new to PowerBI. I want to know how I can split up these entries (all in one line, divided by line breaks) intro three lines with 1, Niklas, 12, Germany / 2, Joe, 14, French / ...

I know that their is this tool "Divide Columns", however doing this for every column, I end up with 27 rows (3*3*3).

I would be so grateful for any ideas / help.

Best Regards

1 ACCEPTED SOLUTION

Ah, now it is clear. Here is one of many ways to do that

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8svMzkksjsnzyk+NyQvJz1XSUTI0iskzNInJM7JIBPLcU4tyE/MqY/LcihLzkoGKggsSM/OUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"House Number" = _t, Country = _t]),
    mix = List.Zip({Text.Split(Source[Name]{0},"#(lf)"),Text.Split(Source[House Number]{0},"#(lf)"),Text.Split(Source[Country]{0},"#(lf)")}),
    #"Converted to Table" = Table.FromList(mix, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Extracted Values" = Table.TransformColumns(#"Converted to Table", {"Column1", each Text.Combine(List.Transform(_, Text.From), "|"), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Column1", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Name", "House Number", "Country"})
in
    #"Split Column by Delimiter"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.

 

 

View solution in original post

13 REPLIES 13
rajendraongole1
Super User
Super User

Hi @Nks_Mr - if possible can you please upload some sample data along with expected output. 

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Nks_Mr_0-1732809085836.png


Hi @rajendraongole1

Hope this is sufficient.

Please show the expected outcome based on the sample data you provided.

Hi @lbendlin ,

I have. See the first screenshot. All the data is in one line / cell divided by Line breaks. But I don't want only one line with line breaks but 3 Lines.

Do you mean that, or do I get something wrong?

Nks_Mr_0-1732810042197.png

 

Ah, now it is clear. Here is one of many ways to do that

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8svMzkksjsnzyk+NyQvJz1XSUTI0iskzNInJM7JIBPLcU4tyE/MqY/LcihLzkoGKggsSM/OUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"House Number" = _t, Country = _t]),
    mix = List.Zip({Text.Split(Source[Name]{0},"#(lf)"),Text.Split(Source[House Number]{0},"#(lf)"),Text.Split(Source[Country]{0},"#(lf)")}),
    #"Converted to Table" = Table.FromList(mix, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Extracted Values" = Table.TransformColumns(#"Converted to Table", {"Column1", each Text.Combine(List.Transform(_, Text.From), "|"), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Column1", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Name", "House Number", "Country"})
in
    #"Split Column by Delimiter"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.

 

 

Hi @lbendlin 

 

With your code it works, however if i use my source, it doesn't work. Having this code: 

let
    Source = Excel.Workbook(File.Contents("myPath"), null, true),
    mix = List.Zip({Text.Split(Source[Name]{0},"#(lf)"),Text.Split(Source[House number]{0},"#(lf)"),Text.Split(Source[Country]{0},"#(lf)")}),
    #"Converted to Table" = Table.FromList(mix, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Extracted Values" = Table.TransformColumns(#"Converted to Table", {"Column1", each Text.Combine(List.Transform(_, Text.From), "|"), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Column1", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Name", "House number", "Country"})
in
    #"Split Column by Delimiter"

 

However I get this Error:  
Expression.Error: The column 'House number' of the table wasn't found.
Details: House number

I also did it without House number and only Name and Country, then it said  column "Country" not found.

Do you have any recommendations?

Thank you very much in advance!

Power Query is case sensitive.  House Number, not House number.

@lbendlin yes, but then I have the same problem. This is my table.

 

Nks_Mr_0-1733152997899.png

 

and this the code:

let
    Source = Excel.Workbook(File.Contents("..."), null, true),
    mix = List.Zip({Text.Split(Source[Name]{0},"#(lf)"),Text.Split(Source[House Number]{0},"#(lf)"),Text.Split(Source[Country]{0},"#(lf)")}),
    #"Converted to Table" = Table.FromList(mix, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Extracted Values" = Table.TransformColumns(#"Converted to Table", {"Column1", each Text.Combine(List.Transform(_, Text.From), "|"), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Column1", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Name", "House Number", "Country"})
in
    #"Split Column by Delimiter"

 

However I still get this mistake: 

Nks_Mr_1-1733153200281.png

 

Do I miss something?

 

 

Please post a sample version of your Excel file.

 

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

 

NameHouse NumberCountry

Niklas

Joe
John

12

14

28a

Germany

Spain

France

You missed promoting the first row as headers.

In general yes, but your link says "Access denied". Please check the sharing settings.

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.