Forum Discussion
Anonymous
4 years agoNot applicable
Pivoting two column with same value
Hi Team, Good Day ! I am trying to pivot multiple columns Column1 with Values1 and Column2 with Values2. However when I'm pivoting Column2 it gives me an error that Column2 data has already e...
- Anonymous4 years ago
Hi Anonymous ,
Please refer the code.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxSSM7PLUjMq1TSUcpJzC0wBNJGBjCOApBhCOIpKMXqRCslp6CpNgLSxjDVxgowvRDVqWloqo2RzTZSgOmFqE7PQFNtArMbxjGBKo4FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [BusinessName = _t, Column1 = _t, Values1 = _t, Column2 = _t, Values2 = _t, #" " = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"BusinessName", type text}, {"Column1", type text}, {"Values1", Int64.Type}, {"Column2", type text}, {"Values2", Int64.Type}, {" ", type text}}), #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Column2", "Values2", " "}), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Column1", "Column"}, {"Values1", "Values"}}) in #"Renamed Columns"Pbix as attached.
Best Regards,
Jay
HotChilli
Community Champion
4 years agoDuplicate the query.
In one version, remove columns (col2, value2). In the other, remove columns (col1, values1) and rename the columns to be column1, values1.
Append the queries and then do the Pivot with aggregate of 'Sum'