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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
coding7
Frequent Visitor

Power Query Unpivot Column

Hi, 

I have this sample table, and I would like to apply an unpivot on the Matched Information Types colmns

 

RepositoryFile NameStatusCommentCurrent LabelCurrent Label IDApplied LabelApplied Label IDCondition NameMatched StringMatched Information TypesLast Modified
Repository 1FileName 1SuccessNo label or action to applyNot set     "[ID Card Number: 342141234,131343124,13511341324,14432561414,134123312], [Drivers License Number: 32424112], [National ID: 2412312312]"2024-02-23 14:18:15Z
Repository 3FileName 3SuccessNo label or action to applyNot set     [Social Welfare Number: 2312321], [Tax Identification Number: 23123]2019-08-09 08:49:58Z

 

The final output would be:

RepositoryFile NameStatusCommentCurrent LabelCurrent Label IDApplied LabelApplied Label IDCondition NameMatched StringAttributevalueMatched Information TypesLast ModifiedLast Modified By
Repository 1FileName 1SuccessNo label or action to applyNot set     ID Card Number342141234,131343124,13511341324,14432561414,134123312"[ID Card Number: 342141234,131343124,13511341324,14432561414,134123312], [Drivers License Number: 32424112], [National ID: 2412312312]"2024-02-23 14:18:15Z
Repository 1FileName 1SuccessNo label or action to applyNot set     Drivers License Number32424112"[ID Card Number: 342141234,131343124,13511341324,14432561414,134123312], [Drivers License Number: 32424112], [National ID: 2412312312]"2024-02-23 14:18:15Z
Repository 1FileName 1SuccessNo label or action to applyNot set     National ID2412312312"[ID Card Number: 342141234,131343124,13511341324,14432561414,134123312], [Drivers License Number: 32424112], [National ID: 2412312312]"2024-02-23 14:18:15Z
Repository 3FileName 3SuccessNo label or action to applyNot set     Social Welfare Number2312321[Social Welfare Number: 2312321], [Tax Identification Number: 23123]2019-08-09 08:49:58Z
Repository 3FileName 3SuccessNo label or action to applyNot set     Tax Identification Number23123[Social Welfare Number: 2312321], [Tax Identification Number: 23123]2019-08-09 08:49:58Z

 

The Matched Information Types column can have more values and columns, it can be arbitrary

Is it possibe to achieve this in power query ?

Thanks a lot !

 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@coding7 here is one way to do this, start a blank query, click advanced editor and paste the M code below. You can follow the same steps on the real data.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rZBBa8MwDIX/ivA5hUp2xsh1YRAYObSDwUIOrquCwY2D7Zb138/2Dl1hx4EFz/KT+fSmSex49dEmH26AohGv1vGoz1wv+4sxHGNWowenD+zAB9AmWb9A8qDX1d3qa4LIKSv4o6ahhxcdjjBezgcOHUhFqJCkalCiVBKpqBazRlm0UpLap+wp/eLMlrmBqQ/2yiHCmzW8RL5/SIoU/nhGXei0g6HvgMpwPXMGoS2pzZY2JAFVh88dtp9ibh4ykL8zkP+Xwd4bm6E+2J10uJNXOsIC/q6/YDjykuzJmrrEo6tsIOb5Gw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Repository = _t, #"File Name" = _t, Status = _t, Comment = _t, #"Current Label" = _t, #"Current Label ID" = _t, #"Applied Label" = _t, #"Applied Label ID" = _t, #"Condition Name" = _t, #"Matched String" = _t, #"Matched Information Types" = _t, #"Last Modified" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Repository", type text}, {"File Name", type text}, {"Status", type text}, {"Comment", type text}, {"Current Label", type text}, {"Current Label ID", type text}, {"Applied Label", type text}, {"Applied Label ID", type text}, {"Condition Name", type text}, {"Matched String", type text}, {"Matched Information Types", type text}, {"Last Modified", type datetime}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Matched Information Types", Splitter.SplitTextByDelimiter("],", QuoteStyle.None), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Matched Information Types"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Matched Information Types", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "New Types", each Text.AfterDelimiter([Matched Information Types], "[")),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Added Custom", "New Types", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Attribute", "Values"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Attribute", type text}, {"Values", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type2",{"Matched Information Types"}),
    #"Replaced Value" = Table.ReplaceValue(#"Removed Columns","]","",Replacer.ReplaceText,{"Values"})
in
    #"Replaced Value"


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

4 REPLIES 4
parry2k
Super User
Super User

@coding7 Awsome - I was about to share a video from my YT channel which talks about Pivoting. Anyhow, glad to hear you have a solution. Cheers!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@coding7 here is one way to do this, start a blank query, click advanced editor and paste the M code below. You can follow the same steps on the real data.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rZBBa8MwDIX/ivA5hUp2xsh1YRAYObSDwUIOrquCwY2D7Zb138/2Dl1hx4EFz/KT+fSmSex49dEmH26AohGv1vGoz1wv+4sxHGNWowenD+zAB9AmWb9A8qDX1d3qa4LIKSv4o6ahhxcdjjBezgcOHUhFqJCkalCiVBKpqBazRlm0UpLap+wp/eLMlrmBqQ/2yiHCmzW8RL5/SIoU/nhGXei0g6HvgMpwPXMGoS2pzZY2JAFVh88dtp9ibh4ykL8zkP+Xwd4bm6E+2J10uJNXOsIC/q6/YDjykuzJmrrEo6tsIOb5Gw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Repository = _t, #"File Name" = _t, Status = _t, Comment = _t, #"Current Label" = _t, #"Current Label ID" = _t, #"Applied Label" = _t, #"Applied Label ID" = _t, #"Condition Name" = _t, #"Matched String" = _t, #"Matched Information Types" = _t, #"Last Modified" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Repository", type text}, {"File Name", type text}, {"Status", type text}, {"Comment", type text}, {"Current Label", type text}, {"Current Label ID", type text}, {"Applied Label", type text}, {"Applied Label ID", type text}, {"Condition Name", type text}, {"Matched String", type text}, {"Matched Information Types", type text}, {"Last Modified", type datetime}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Matched Information Types", Splitter.SplitTextByDelimiter("],", QuoteStyle.None), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Matched Information Types"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Matched Information Types", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "New Types", each Text.AfterDelimiter([Matched Information Types], "[")),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Added Custom", "New Types", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Attribute", "Values"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Attribute", type text}, {"Values", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type2",{"Matched Information Types"}),
    #"Replaced Value" = Table.ReplaceValue(#"Removed Columns","]","",Replacer.ReplaceText,{"Values"})
in
    #"Replaced Value"


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Sorry @parry2k , I already got it, I just followed this video Pivot Two Columns to Multiple Columns with Power Query (youtube.com) 

Thanks a lot @parry2k is working perfectly ✌️

Just a small question, if I want to later pivot the columns 'Attribute' and 'Values' with the rest, do you know how to apply it?

For example:

ID Card Number Drivers License Number National ID Social Welfare Number Tax Identification Number

342141234,131343124,13511341324,14432561414,134123312324241122412312312231232123123


Once again, thank you for everything

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.