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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
JNelson
Helper II
Helper II

Split column then pivot back

Hello,

 

Unfortunately I have a lot of messy data to cleanse. 

We get job order information with the date, job number, products (anywhere from 1 to 5 products) and quantities associated with the aforementioned products. 

I have managed to split out the cell to multiple columns by using the split by delimiter function. However the desired outcome would have all products in one column and it's corresponding quanitity in another. I have tried pivoting/unpivoting, but I'm lost. Would appreciate any ideas how to tackle this.

 

Thanks

 

JNelson_0-1669173357761.png

 

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

NewStep=#table(Table.ColumnNames(PreviousStepName),List.TransformMany(Table.ToRows(PreviousStepName),each List.Zip(List.Transform(List.Skip(_,2),each Text.Split(_,"/"))),(x,y)=>List.FirstN(x,2)&y))

View solution in original post

4 REPLIES 4
wdx223_Daniel
Super User
Super User

NewStep=#table(Table.ColumnNames(PreviousStepName),List.TransformMany(Table.ToRows(PreviousStepName),each List.Zip(List.Transform(List.Skip(_,2),each Text.Split(_,"/"))),(x,y)=>List.FirstN(x,2)&y))

Hi @wdx223_Daniel 

As I only provided a sample of the data in my original post, I've gone on to attempt to use it with live data and there are some cells (in other columns) that are blank (null) in the query and that is causing it to error. Is there a way I can work around this without having to get rid of the null values. For example, there will not always be a job number assigned so the cell will be blank..

 

Thanks again for the start on the code.

 

NewStep=#table(Table.ColumnNames(PreviousStepName),List.TransformMany(Table.ToRows(PreviousStepName),each List.Zip(List.Transform(List.Skip(_,2),each if _=null then {null} else Text.Split(_,"/"))),(x,y)=>List.FirstN(x,2)&y))

You're a wizard! Thank you so much. Works perfectly!!

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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