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
maclura
Resolver I
Resolver I

Unpivoting multiple measures indefinitely repeated

Hi,

I found several posts on how to unpivot in the most diverse situation, but not in this one.

 

I have a table like the below

maclura_0-1621857291003.png

where the "Code", "Type" and "Score" triplets can be repeated an undefined number of time (the same for all rows).

 

What is the smartest way to transform this tabe in the following?

maclura_1-1621857426223.png

 

Thank you for any hint

2 ACCEPTED SOLUTIONS
mahoneypat
Microsoft Employee
Microsoft Employee

Please see this video for one way to handle the transform for repeating columns like this.

(11) Faster Data Transformations with List/Record M Functions - YouTube

 

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


View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nQxVNJRMjTSNTDWNTIwAnGcQISnXwiQNAFxjeBcYxDXGM41UorVAZlghNUEP0cgAdMP5xjDORC9xlj1ukZAzIfqhnBNYPohXFOl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Date Sent" = _t, Code1 = _t, Type1 = _t, Score1 = _t, Code2 = _t, Type2 = _t, Score2 = _t, Code3 = _t, Type3 = _t, Score3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Date Sent", type date}, {"Code1", type text}, {"Type1", type text}, {"Score1", Int64.Type}, {"Code2", type text}, {"Type2", type text}, {"Score2", Int64.Type}, {"Code3", type text}, {"Type3", type text}, {"Score3", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID", "Date Sent"}, "Attribute", "Value"),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Attribute.1", "Attribute.2"}),
    #"Pivoted Column" = Table.Pivot(#"Split Column by Character Transition", List.Distinct(#"Split Column by Character Transition"[Attribute.1]), "Attribute.1", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Attribute.2"})
in
    #"Removed Columns"

Hope this helps.

Untitled.png

The headings of the source dataset should be

Untitled1.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nQxVNJRMjTSNTDWNTIwAnGcQISnXwiQNAFxjeBcYxDXGM41UorVAZlghNUEP0cgAdMP5xjDORC9xlj1ukZAzIfqhnBNYPohXFOl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Date Sent" = _t, Code1 = _t, Type1 = _t, Score1 = _t, Code2 = _t, Type2 = _t, Score2 = _t, Code3 = _t, Type3 = _t, Score3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Date Sent", type date}, {"Code1", type text}, {"Type1", type text}, {"Score1", Int64.Type}, {"Code2", type text}, {"Type2", type text}, {"Score2", Int64.Type}, {"Code3", type text}, {"Type3", type text}, {"Score3", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID", "Date Sent"}, "Attribute", "Value"),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Attribute.1", "Attribute.2"}),
    #"Pivoted Column" = Table.Pivot(#"Split Column by Character Transition", List.Distinct(#"Split Column by Character Transition"[Attribute.1]), "Attribute.1", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Attribute.2"})
in
    #"Removed Columns"

Hope this helps.

Untitled.png

The headings of the source dataset should be

Untitled1.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
mahoneypat
Microsoft Employee
Microsoft Employee

Please see this video for one way to handle the transform for repeating columns like this.

(11) Faster Data Transformations with List/Record M Functions - YouTube

 

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


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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.