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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register 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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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