Forum Discussion
Transpose / Pivot data
- Anonymous3 years ago
Hi Anonymous ,
I have created a simple sample , please refer to my pbix file to see if it helps you.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TZE9SwNBEIb/y9UJ7HzvlDYWAbWwDCmScKgQk3DeCf57d2dOsNqFe+ad597d74fd8bocp59hM2AV7AdV4KLt5kbczy2RFaE6HDb74XE8TX8DjtQPdkHnGDCp6wA6cAw8Hafze8SbJm2o0G4AphGwJVAHSvzhPn1cAte0UdUIbUsyvH8B8TU8RShYRrHSEx0USyRzlaYS7G65jgF7WAu2PA6PYlWCFqlSYaUvPZpKgYgWo2KdRtCa1q0TMkrr5W35mjsPJVREikn+Janb6oJtefCv430eP0/jFCOSQooVu0dFYshemM2z95fzfFt5jNfB1gtT54GAPB8KRIvkwPPt+9+GrB4EohesxTG6dBah5nT4BQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Month = _t, Members = _t, #"Sum of Funds" = _t, #"Sum of Adjust" = _t, #"Sum of TotalExp" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", type text}, {"Members", Int64.Type}, {"Sum of Funds", Int64.Type}, {"Sum of Adjust", Int64.Type}, {"Sum of TotalExp", Int64.Type}}), #"Transposed Table" = Table.Transpose(#"Changed Type"), #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]), #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"January", Int64.Type}, {"February", Int64.Type}, {"March", Int64.Type}, {"April", Int64.Type}, {"May", Int64.Type}, {"June", Int64.Type}, {"July", Int64.Type}, {"August", Int64.Type}, {"September", Int64.Type}, {"October", Int64.Type}, {"November", Int64.Type}}), #"Added Index" = Table.AddIndexColumn(#"Changed Type1", "Index", 1, 1, Int64.Type) in #"Added Index"let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8k3NTUotKlaK1YlWCi7NVchPU3ArzUtBEXBMySotLkEWCckvScxxrShQio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Month = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", type text}}), #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type) in #"Added Index"let Source = Table.NestedJoin(Table, {"Index"}, #"Table (2)", {"Index"}, "Table (2)", JoinKind.LeftOuter), #"Expanded Table (2)" = Table.ExpandTableColumn(Source, "Table (2)", {"Month"}, {"Month"}), #"Reordered Columns" = Table.ReorderColumns(#"Expanded Table (2)",{"Month", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "Index"}), #"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Index"}) in #"Removed Columns"How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .
Best Regards
Community Support Team _ PollyIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
I have created a simple sample , please refer to my pbix file to see if it helps you.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TZE9SwNBEIb/y9UJ7HzvlDYWAbWwDCmScKgQk3DeCf57d2dOsNqFe+ad597d74fd8bocp59hM2AV7AdV4KLt5kbczy2RFaE6HDb74XE8TX8DjtQPdkHnGDCp6wA6cAw8Hafze8SbJm2o0G4AphGwJVAHSvzhPn1cAte0UdUIbUsyvH8B8TU8RShYRrHSEx0USyRzlaYS7G65jgF7WAu2PA6PYlWCFqlSYaUvPZpKgYgWo2KdRtCa1q0TMkrr5W35mjsPJVREikn+Janb6oJtefCv430eP0/jFCOSQooVu0dFYshemM2z95fzfFt5jNfB1gtT54GAPB8KRIvkwPPt+9+GrB4EohesxTG6dBah5nT4BQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Month = _t, Members = _t, #"Sum of Funds" = _t, #"Sum of Adjust" = _t, #"Sum of TotalExp" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", type text}, {"Members", Int64.Type}, {"Sum of Funds", Int64.Type}, {"Sum of Adjust", Int64.Type}, {"Sum of TotalExp", Int64.Type}}),
#"Transposed Table" = Table.Transpose(#"Changed Type"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
#"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"January", Int64.Type}, {"February", Int64.Type}, {"March", Int64.Type}, {"April", Int64.Type}, {"May", Int64.Type}, {"June", Int64.Type}, {"July", Int64.Type}, {"August", Int64.Type}, {"September", Int64.Type}, {"October", Int64.Type}, {"November", Int64.Type}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type1", "Index", 1, 1, Int64.Type)
in
#"Added Index"let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8k3NTUotKlaK1YlWCi7NVchPU3ArzUtBEXBMySotLkEWCckvScxxrShQio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Month = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", type text}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type)
in
#"Added Index"let
Source = Table.NestedJoin(Table, {"Index"}, #"Table (2)", {"Index"}, "Table (2)", JoinKind.LeftOuter),
#"Expanded Table (2)" = Table.ExpandTableColumn(Source, "Table (2)", {"Month"}, {"Month"}),
#"Reordered Columns" = Table.ReorderColumns(#"Expanded Table (2)",{"Month", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "Index"}),
#"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Index"})
in
#"Removed Columns"
How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .
Best Regards
Community Support Team _ Polly
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.