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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
mds123
Frequent Visitor

Splitting semi colon separated columns into rows

Hello,

My data source is a list of work orders. Two of my columns in my dataset have semi colons to separate the item codes and quantities that are in the same work order. My goal is to break this items and corresponding quantities out onto different rows. This way, each work order / item code combination is its own row. 

 

This is how the data arrives to me and I can not change how it arrives.

DateSiteWork OrderItem CodesQuantities
1/1/2024

CA

1A1234; 121;2
1/1/2024NY1B2535
1/2/2024FL2C1234; 15; 95;2;3

 

The most items in one work order is likely five but there is no hard limit. My goal is to format the data like this:

 

DateSiteWork OrderItem CodeQuantity
1/1/2024CA1A12341
1/1/2024CA1A122
1/1/2024NY1B2535
1/2/2024FL2C12345
1/2/2024FL2C152
1/2/2024FL2C93

 

I'm very lost at how to do this in power query. I tried joining it onto itself in different ways but that did not help.

Any help is appreciated!

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJR0lFydgQShmDCyNjEWsHQCMS0NlKK1UFR5xcJEncCEkamQMLYFKrACKbAzQck54wwyNRawRLIM7U2sjZWio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Site = _t, #"Work Order" = _t, #"Item Codes" = _t, Quantities = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Site", type text}, {"Work Order", type text}, {"Item Codes", type text}, {"Quantities", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Zip({Text.Split([Item Codes],";"),Text.Split([Quantities],";")})),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Date", "Site", "Work Order", "Custom"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Removed Other Columns", "Custom"),
    #"Extracted Values" = Table.TransformColumns(#"Expanded Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Custom", Splitter.SplitTextByEachDelimiter({";"}, QuoteStyle.Csv, false), {"Item Code", "Quantity"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Item Code", Int64.Type}, {"Quantity", Int64.Type}})
in
    #"Changed Type1"

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 Source step with your own source.

View solution in original post

2 REPLIES 2
mds123
Frequent Visitor

If anyone has a similar question, I used this video to solve it. It took maybe 5 minutes. https://www.youtube.com/watch?v=JMOnr3DOqyk 

lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJR0lFydgQShmDCyNjEWsHQCMS0NlKK1UFR5xcJEncCEkamQMLYFKrACKbAzQck54wwyNRawRLIM7U2sjZWio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Site = _t, #"Work Order" = _t, #"Item Codes" = _t, Quantities = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Site", type text}, {"Work Order", type text}, {"Item Codes", type text}, {"Quantities", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Zip({Text.Split([Item Codes],";"),Text.Split([Quantities],";")})),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Date", "Site", "Work Order", "Custom"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Removed Other Columns", "Custom"),
    #"Extracted Values" = Table.TransformColumns(#"Expanded Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Custom", Splitter.SplitTextByEachDelimiter({";"}, QuoteStyle.Csv, false), {"Item Code", "Quantity"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Item Code", Int64.Type}, {"Quantity", Int64.Type}})
in
    #"Changed Type1"

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 Source step with your own source.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors