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
EllieSim
Helper II
Helper II

Combine multiple columns into several columns based on delimited values

Hello,

 

I am trying to combine a number of split columns (using a delimiter) into several columns (based on their original headings) in the Query Editor.

 

This is what the original table looks like before splitting:

 

ItemIssue NameIssue DistributionReason for IssueCompleted
Item1COI;COI;HW1;HW2Name1;Name2;Name 3;Name4For Information;For Comment;For Comment;For Validation31.08.2020;None;None;None
Item2nullnullnullnull

 

This is the table once split by delimiter:

ItemIssue Name.1Issue Name.2Issue Name.3Issue Name.4Issue Distribution.1Issue Distribution.2Issue Distribution.3Issue Distribution.4Reason For Issue.1Reason For Issue.2Reason For Issue.3Reason For Issue.4Completed.1Completed.2Completed.3Completed.4
Item1COICOIHW1HW2Name.1Name.2Name.3Name.4For InformationFor CommentFor CommentFor Validation31.08.2020NoneNoneNone
Item2nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull

 

Here is the table I am hoping to achieve in The Query Editor:

 

ItemIssue NameIssue DistributionReason for IssueCompleted
Item 1COIName1For Information2008.2020
Item 1COIName2For CommentNone
Item1HW1Name3For CommentNone
Item1HW2Name4For ValidationNone
Item2nullnullnullnull
Item2etc...   

 

Alternatively, is there a DAX expression I can use to return multiple rows in a table output as above?

 

Many thanks for your help.

1 ACCEPTED SOLUTION

@EllieSim

Unfortunately, I cannot add a file directly to the forum. I can only by using some file hosting.

 

With your dataset, apply this code in Power Query.

let
    Source = [your source],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", type text}, {"Issue Name", type text}, {"Issue Distribution", type text}, {"Reason for Issue", type text}, {"Completed", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Issue Name Split", each Text.Split([Issue Name],";")),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Issue Distribution Split", each Text.Split([Issue Distribution],";")),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Reason Split", each Text.Split([Reason for Issue],";")),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Completed Split", each Text.Split([Completed],";")),
    #"Added Custom4" = Table.AddColumn(#"Added Custom3", "New Table", each Table.FromColumns({[Issue Name Split],[Issue Distribution Split],[Reason Split],[Completed Split]})),
    #"Expanded New Table" = Table.ExpandTableColumn(#"Added Custom4", "New Table", {"Column1", "Column2", "Column3", "Column4"}, {"New Table.Column1", "New Table.Column2", "New Table.Column3", "New Table.Column4"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded New Table",{"Issue Name", "Issue Distribution", "Reason for Issue", "Completed", "Issue Name Split", "Issue Distribution Split", "Reason Split", "Completed Split"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"New Table.Column1", "Issue Name"}, {"New Table.Column2", "Issue Distribution"}, {"New Table.Column3", "Reason for Issue"}, {"New Table.Column4", "Completed"}})
in
    #"Renamed Columns"

 

 

Or, if you want, I can add this file to some drive. Let me know.



_______________
If I helped, please accept the solution and give kudos! 😀

 

View solution in original post

10 REPLIES 10
Alexander76877
Helper II
Helper II

 

Hi,  some have pointed out you need to unpivot all others than "item".

That´s correct but not the full solution. After that, you need to split the attribute by "." to and again pivot by this index.  Then you get your result.

2020-08-31 13_17_50-Untitled - Power Query Editor.png

Please find the code below. 

Please mark as solution if that´s the correct answer to your question.

Alexander

------------

 

let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8ixJzTVU0lFy9veEkx7hhmDSCEj6Jeam6hnCGHARYxjDBMhwyy9S8MxLyy/KTSzJzM+Dijjn5+am5pVg5YUl5mSmwBQbG+oZWOgZGRgZgAzNz0tFo2J1IM4EWZ5XmpNDAYUFxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t, #"Issue Name.1" = _t, #"Issue Name.2" = _t, #"Issue Name.3" = _t, #"Issue Name.4" = _t, #"Issue Distribution.1" = _t, #"Issue Distribution.2" = _t, #"Issue Distribution.3" = _t, #"Issue Distribution.4" = _t, #"Reason For Issue.1" = _t, #"Reason For Issue.2" = _t, #"Reason For Issue.3" = _t, #"Reason For Issue.4" = _t, Completed.1 = _t, Completed.2 = _t, Completed.3 = _t, Completed.4 = _t]), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Item"}, "Attribute", "Value"), #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"Header", "Index"}), #"Pivoted Column" = Table.Pivot(#"Split Column by Delimiter", List.Distinct(#"Split Column by Delimiter"[Header]), "Header", "Value"), #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Index"}) in #"Removed Columns"

 

 

Hello,

Thanks for your reply.

Unpivitong the columns removes all the null (Items with no value), when I pivot the Attribute columns this produces errors. Is there a way around this?

Many thanks

That is correct. You need to replace null values by "" empty values before splitting the columns.

Please mark as solution if that´s the correct answer to your question.

Alexander

@EllieSim, please check my file. Null values were preserved.
FarhanAhmed
Community Champion
Community Champion

This is the table once split by delimiter:

ItemIssue Name.1Issue Name.2Issue Name.3Issue Name.4Issue Distribution.1Issue Distribution.2Issue Distribution.3Issue Distribution.4Reason For Issue.1Reason For Issue.2Reason For Issue.3Reason For Issue.4Completed.1Completed.2Completed.3Completed.4
Item1COICOIHW1HW2Name.1Name.2Name.3Name.4For InformationFor CommentFor CommentFor Validation31.08.2020NoneNoneNone
Item2nullnullnullnullnullnullnullnullnullnullnullnullnullnull

 

After above step . right click on "Items" and click "Unpivot Other Columns" and you will get the desired results.

 

 







Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!

Proud to be a Super User!




lkalawski
Memorable Member
Memorable Member

Hi @EllieSim ,

 

You can use Table.Split function in Power Query. I prepared the file for you with the solution:

https://gofile.io/d/kT1VOZ

lkalawski_0-1598868402711.png

 



_______________
If I helped, please accept the solution and give kudos! 😀

Hello,

I am not able to download the file for some reason. Is it possibe to upload it here instead?

Many thanks 🙂

@EllieSim

Unfortunately, I cannot add a file directly to the forum. I can only by using some file hosting.

 

With your dataset, apply this code in Power Query.

let
    Source = [your source],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", type text}, {"Issue Name", type text}, {"Issue Distribution", type text}, {"Reason for Issue", type text}, {"Completed", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Issue Name Split", each Text.Split([Issue Name],";")),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Issue Distribution Split", each Text.Split([Issue Distribution],";")),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Reason Split", each Text.Split([Reason for Issue],";")),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Completed Split", each Text.Split([Completed],";")),
    #"Added Custom4" = Table.AddColumn(#"Added Custom3", "New Table", each Table.FromColumns({[Issue Name Split],[Issue Distribution Split],[Reason Split],[Completed Split]})),
    #"Expanded New Table" = Table.ExpandTableColumn(#"Added Custom4", "New Table", {"Column1", "Column2", "Column3", "Column4"}, {"New Table.Column1", "New Table.Column2", "New Table.Column3", "New Table.Column4"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded New Table",{"Issue Name", "Issue Distribution", "Reason for Issue", "Completed", "Issue Name Split", "Issue Distribution Split", "Reason Split", "Completed Split"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"New Table.Column1", "Issue Name"}, {"New Table.Column2", "Issue Distribution"}, {"New Table.Column3", "Reason for Issue"}, {"New Table.Column4", "Completed"}})
in
    #"Renamed Columns"

 

 

Or, if you want, I can add this file to some drive. Let me know.



_______________
If I helped, please accept the solution and give kudos! 😀

 

FarhanAhmed
Community Champion
Community Champion

Is your data is consistent ? I mean number of delimated values are fixed & upto 4 ? right ?

 







Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!

Proud to be a Super User!




amitchandak
Super User
Super User

Helpful resources

Announcements
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.