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
rjtedge
Frequent Visitor

Transposing data to new table

daHi, 

I have a table that looks like this:

DivisionReport MonthIncidents (current)Incidents (Past)Reports (currents)Reports (past)
Division 11/10/2021109810
Division 21/10/202112453

 

I would like to transpose the data to create a new table that looks like the one below but can't work out how to get it working with Dax. Any suggestions?

StatCurrentPastDivisionReport Month
Incidents109Division 11/10/2021
Reports810Division 11/10/2021
Incidents124Division 21/10/2021
Reports53Division 21/10/2021

 

Thanks

 

Rob

1 ACCEPTED SOLUTION
FarhanAhmed
Community Champion
Community Champion

 

Make sure that your names in columns are Matched and case sensitive...

eg. current & currents are 2 different

eg 2. Past & past are 2 different.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsksyyzOzM9TMFTSUTLUNzTQNzIwArMNgIQlEFtAOLE6SIqN0BWDBEyA2BSIjZViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Division = _t, #"Report Month" = _t, #"Incidents (current)" = _t, #"Incidents (past)" = _t, #"Reports (current)" = _t, #"Reports (past)" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Division", type text}, {"Report Month", type date}, {"Incidents (current)", Int64.Type}, {"Incidents (past)", Int64.Type}, {"Reports (current)", Int64.Type}, {"Reports (past)", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Division", "Report Month"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByEachDelimiter({"("}, QuoteStyle.Csv, false), {"Attribute.1", "Attribute.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type1",")","",Replacer.ReplaceText,{"Attribute.2"}),
    #"Pivoted Column" = Table.Pivot(#"Replaced Value", List.Distinct(#"Replaced Value"[Attribute.2]), "Attribute.2", "Value", List.Sum),
    #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Attribute.1", "Stat"}})
in
    #"Renamed Columns"

 

FarhanAhmed_0-1638333348642.png

 







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

Proud to be a Super User!




View solution in original post

1 REPLY 1
FarhanAhmed
Community Champion
Community Champion

 

Make sure that your names in columns are Matched and case sensitive...

eg. current & currents are 2 different

eg 2. Past & past are 2 different.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsksyyzOzM9TMFTSUTLUNzTQNzIwArMNgIQlEFtAOLE6SIqN0BWDBEyA2BSIjZViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Division = _t, #"Report Month" = _t, #"Incidents (current)" = _t, #"Incidents (past)" = _t, #"Reports (current)" = _t, #"Reports (past)" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Division", type text}, {"Report Month", type date}, {"Incidents (current)", Int64.Type}, {"Incidents (past)", Int64.Type}, {"Reports (current)", Int64.Type}, {"Reports (past)", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Division", "Report Month"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByEachDelimiter({"("}, QuoteStyle.Csv, false), {"Attribute.1", "Attribute.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type1",")","",Replacer.ReplaceText,{"Attribute.2"}),
    #"Pivoted Column" = Table.Pivot(#"Replaced Value", List.Distinct(#"Replaced Value"[Attribute.2]), "Attribute.2", "Value", List.Sum),
    #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Attribute.1", "Stat"}})
in
    #"Renamed Columns"

 

FarhanAhmed_0-1638333348642.png

 







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

Proud to be a Super User!




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.