Forum Discussion
Unpivot Columns
Here is the link to the data: https://docs.google.com/spreadsheets/d/1EMqc3KrH2J6k5LpQakikSZIH3MgHvpNHu6gZwpYuY40/edit?usp=sharing
I tried the Unpivot Other Columns, but it didn't work out.
Hello,
You need more than Unpivoting for your use case. Try the M-Script below.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("vZJBa8MwDIX/ishpg8az5diJeytjG2XdUprcQg9u6tJCSIcdyn7+5JYx2NnU8FmCKLzk6XVdtnF2gNrvnQ/ZLBMEEpIoCEVooiQqwsQZHq84KTDbzrpMSTSCA6z9AZpLH2DjLvQ015wO4/xfn6JEWW04Gg2wsrs5vHxPzo92iN/JEP9KOjXkqADqi/NHZ/dz+DiFHh4Gu3uMVrDy6hmTVUJRpQU3XAC8t8t83daQw+tp5zy8rRZNE30VWpYlK8prL6QUDIuUf82V4gbg+TxO3vZTyOvpSPpxzdFjKZmK2oXRyETS7RYKOYWqWdJuv9wYHLTejuFwCyr+pkncLVc0oK+lMvfLlZRcMRPfkAbNzexU0kaJAtGQye2yyRdPnzlAsIMLh7Pv3c3kSrAqBhsrzSUzMpX89gc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t, Column9 = _t, Column10 = _t, Column11 = _t, Column12 = _t, Column13 = _t]),
#"Transposed Table" = Table.Transpose(Source),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Transposed Table", {"Column1"}, "Attribute", "Value"),
#"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Value", type text}}),
RealOrdersName = Table.SelectRows(#"Changed Type", each ([Column1] = "Real Orders")),
Custom1 = #"Unpivoted Other Columns",
#"Filtered Rows1" = Table.SelectRows(Custom1, each [Column1] <> "Real Orders"),
#"Merged Queries" = Table.NestedJoin(#"Filtered Rows1", {"Attribute"}, RealOrdersName, {"Attribute"}, "ColumnName", JoinKind.LeftOuter),
#"Expanded ColumnName" = Table.ExpandTableColumn(#"Merged Queries", "ColumnName", {"Value"}, {"Real Orders"}),
#"Renamed Columns" = Table.RenameColumns(#"Expanded ColumnName",{{"Column1", "Period"}, {"Value", "Amount"}}),
#"Removed Other Columns" = Table.SelectColumns(#"Renamed Columns",{"Real Orders", "Amount", "Period"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Removed Other Columns",{{"Amount", type number}, {"Period", Int64.Type}}),
#"Sorted Rows" = Table.Sort(#"Changed Type1",{{"Period", Order.Ascending}})
in
#"Sorted Rows"Here's a screenshot of the result:
Sample PBIX - https://drive.google.com/file/d/1TD1fOdwaxP2pVDPp2goKprXVIno9rkch/view?usp=sharing
- Anonymous4 years agoNot applicable
Thank you for working on this and sorry for the delayed reply. Would it be possible to have the desired result data in the same sort order (Real Order column) as the original data?
- v-xiaotang4 years agoCommunity Support
Hi Anonymous
I just want to confirm if you resolved this issue? If yes, you can accept the answer helpful as the solution or share you method and accept it as solution, thanks for your contribution to improve Power BI.
If you need more help, please let me know.
Best Regards,
Community Support Team _Tang
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous4 years agoNot applicable
Hi,
I am just waiting to have the desired result data in the same sort order (Real Order column) as the original data. At the moment, I have not been able to resolve the issue.