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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
scoobymoo
Frequent Visitor

Splitting multiple columns using delimiter

Hi

 

I have a table that has several columns with delimiters. I need to split the columns into rows and maintain the order of the values in each column. I know how to split one column into rows using the delimiters but can't seem to do this successfully with multiple columns and maintain the order. Is this possible?

 

Thank you

 

Example. I need to split this:

 

Person IDTypeOrder IDDate of TransactionDate of Payment
001Blue100,10101/01/18, 02/01/1802/01/18, 03/01/18
002Blue102,103,10401/01/18, 01/01/18, 02/01/1802/01/18, 02/01/18, 03/01/18
003Red105,10601/12/2016, 13/04/201502/12/2016, 13/04/2015

 

Into this:

 

Person IDTypeOrder IDDate of TransactionDate of Payment
001Blue10001/01/201802/01/2018
001Blue10102/01/201803/01/2018
002Blue10201/01/201802/01/2018
002Blue10301/01/201802/01/2018
002Blue10402/01/201803/01/2018
003Red10501/01/201802/01/2018
003Red10602/01/201803/01/2018
1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

I'd go for this solution: Add a column that creates an expandable table from the relevant columns.

 

Table.FromColumns({Text.Split([Order ID], ","), Text.Split([Date of Transaction], ","), Text.Split([Date of Payment], ",") }, {"OrderIDs", "Transactions", "Payments"} )

 

To see how this works, you can paste this code into the advanced editor and follow the steps:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hcw9CoAwDAXgq5TMgealPzh7BNfSzW6u3t/UiigIQkLCS/hKIRDTvO3NBkQY0gOBt8LETnRsPdQ7DFdYuZA+ATUgWMc38sN9w8GelraebjIzDxPqVZDZwZ5j39PQvg61Hg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Person ID" = _t, Type = _t, #"Order ID" = _t, #"Date of Transaction" = _t, #"Date of Payment" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each Table.FromColumns({Text.Split([Order ID], ","), Text.Split([Date of Transaction], ","), Text.Split([Date of Payment], ",") }, {"OrderIDs", "Transactions", "Payments"} )),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"OrderIDs", "Transactions", "Payments"}, {"OrderIDs", "Transactions", "Payments"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Transactions", type date}, {"Payments", type date}})
in
    #"Changed Type1"

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

6 REPLIES 6
ImkeF
Super User
Super User

I'd go for this solution: Add a column that creates an expandable table from the relevant columns.

 

Table.FromColumns({Text.Split([Order ID], ","), Text.Split([Date of Transaction], ","), Text.Split([Date of Payment], ",") }, {"OrderIDs", "Transactions", "Payments"} )

 

To see how this works, you can paste this code into the advanced editor and follow the steps:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hcw9CoAwDAXgq5TMgealPzh7BNfSzW6u3t/UiigIQkLCS/hKIRDTvO3NBkQY0gOBt8LETnRsPdQ7DFdYuZA+ATUgWMc38sN9w8GelraebjIzDxPqVZDZwZ5j39PQvg61Hg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Person ID" = _t, Type = _t, #"Order ID" = _t, #"Date of Transaction" = _t, #"Date of Payment" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each Table.FromColumns({Text.Split([Order ID], ","), Text.Split([Date of Transaction], ","), Text.Split([Date of Payment], ",") }, {"OrderIDs", "Transactions", "Payments"} )),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"OrderIDs", "Transactions", "Payments"}, {"OrderIDs", "Transactions", "Payments"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Transactions", type date}, {"Payments", type date}})
in
    #"Changed Type1"

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Worked like a charm for me! Thank you so much

Brilliant, thanks

I'm a total newbie to PowerBi - this was the first file I uploaded so it took me a while to figure out the code with my actual work related fields but this worked brilliantly! Thank you!

Sean
Community Champion
Community Champion

So if anyone is following @ImkeF's steps in a Different Locale ( for example US ) just change the last step to include "en-GB"

and the error you may be getting in the last row will be gone!

 

...
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom", {{"Transactions", type date},
{"Payments", type date}}, "en-GB")
in
    #"Changed Type1"

 

Alternatively you could delete the last Step in the Applied Steps in the Query Editor

then Ctrl+select both Transactions and Payments columns

right-click either column header - Change Type - Using Locale... - Data Type: Date - Locale: English (UK)

and that would generate the "en-GB" to convert the European dates to US format Smiley Happy

Greg_Deckler
Super User
Super User

Yeesh! @ImkeF.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.