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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PhoenixBird66
Helper III
Helper III

Please help -should I Pivot or Split by Delimiter?

Hi Guys,

 

I've got some data which is really messy. In some columns we have multiple values separated with a comma, and then in another column they have percentages also separated with a comma, like in the image below.

 

PhoenixBird66_0-1608122480699.png

 

I need to be able to match up the percentage with the correct process - so for ID 1234 I need 3 lines of data:

 

Annealing is 20%

Brazing is 20% 

Canning is 60%

 

I dont know how best to do this -should I split the columns by delimiter, or should I be unpivoting them?

1 ACCEPTED SOLUTION
v-yuaj-msft
Community Support
Community Support

Hi,

Based on your description, you can do some steps as follows.

1217.gif

 

 

Result:

v-yuaj-msft_0-1608512902984.png

 

Hope that's what you were looking for.

Best Regards,

Yuna

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

6 REPLIES 6
v-yuaj-msft
Community Support
Community Support

Hi,

Based on your description, you can do some steps as follows.

1217.gif

 

 

Result:

v-yuaj-msft_0-1608512902984.png

 

Hope that's what you were looking for.

Best Regards,

Yuna

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

mahoneypat
Employee
Employee

Did you try the approach in my suggestion?  It should even with mutliple columns with comma delimited lists in them.  You would just add a third Text.Split inside the List.Zip part, and a third column name inside the Record.FromList part.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


I did try it, thanks. However I'm not good with M code (I'm not that advanced) and I dont know how to apply what you've given me to the data in my table? 😞

It'd be easier for me to do manual steps - but I dont understand which step to do first. 

mahoneypat
Employee
Employee

Here is another way to do in the query editor in mostly one step, making a custom column that makes a List of Records from the columns.  I did an example with letters and numbers, but note that both input column need to be text format (you can convert to number after, if needed).

To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Hci3DcAwEATBXi7ehKRsKEOZGh7ffxs6KBrsRqgIbewctlBpSkLVddK57MDI9N/munl47czCqswP", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Letters = _t, Numbers = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Letters", type text}, {"Numbers", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Transform(List.Zip({Text.Split([Letters],","), Text.Split([Numbers],",")}), each Record.FromList(_, {"Letter", "Number"}))),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Letters", "Numbers"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Removed Columns", "Custom"),
    #"Expanded Custom1" = Table.ExpandRecordColumn(#"Expanded Custom", "Custom", {"Letter", "Number"}, {"Letter", "Number"})
in
    #"Expanded Custom1"

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


HotChilli
Super User
Super User

The answer is -> both.

The pattern for these things is :

Split the columns

Select the key column (the first here) and Unpivot other columns.

You will get an Attribute column which holds information that we can use (1,2,3 or column2 column3)

Split the Attribute column (on ".")

You then Pivot the Attribute.1 column. Use Value in Values and choose Advanced-> Don't Aggregate.

 

Let me know how you get on

 

Thanks for your input on this. 

 

Unfortunately it's a little more complicated than I mentioned earlier because there's an additional column with more then one value in (so that also needs to be split somehow)

This is where I've got it to now. Not sure which columns should be unpivoted and split and pivoted again and in what order?

 

PhoenixBird66_0-1608139647784.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors