Forum Discussion
Pivoting Error
- 4 years ago
Here you go if you want to do it PQ. the trick is you have to tell PQ that every 4 rows should be treated as a single row after pivoting. so I have added index,divide and round up. use the code that i have pasted at last.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsssKilNzPFNTM7IzEstVtJRcjQEEmXOAaEgjqFSrA5ORb6puflFlSBVeuam+BSCTUssS8zMSUzKSSVkLEh1cEFqUXJ+EVFqQRwjotxpRKo78RqL5k6g2lgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [resourcetype = _t, valuename = _t, capabilitiesname = _t, capabilityvalue = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"resourcetype", type text}, {"valuename", type text}, {"capabilitiesname", type text}, {"capabilityvalue", type number}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
#"Inserted Modulo" = Table.AddColumn(#"Added Index", "Modulo", each Number.Mod([Index], 4), type number),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Modulo",{"Modulo"}),
#"Divided Column" = Table.TransformColumns(#"Removed Columns", {{"Index", each _ / 4, type number}}),
#"Rounded Up" = Table.TransformColumns(#"Divided Column",{{"Index", Number.RoundUp, Int64.Type}}),
#"Pivoted Column" = Table.Pivot(#"Rounded Up", List.Distinct(#"Rounded Up"[capabilitiesname]), "capabilitiesname", "capabilityvalue")
in
#"Pivoted Column"Thanks,
thingsclump
accpet solution if this works for you.
Here you go if you want to do it PQ. the trick is you have to tell PQ that every 4 rows should be treated as a single row after pivoting. so I have added index,divide and round up. use the code that i have pasted at last.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsssKilNzPFNTM7IzEstVtJRcjQEEmXOAaEgjqFSrA5ORb6puflFlSBVeuam+BSCTUssS8zMSUzKSSVkLEh1cEFqUXJ+EVFqQRwjotxpRKo78RqL5k6g2lgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [resourcetype = _t, valuename = _t, capabilitiesname = _t, capabilityvalue = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"resourcetype", type text}, {"valuename", type text}, {"capabilitiesname", type text}, {"capabilityvalue", type number}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
#"Inserted Modulo" = Table.AddColumn(#"Added Index", "Modulo", each Number.Mod([Index], 4), type number),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Modulo",{"Modulo"}),
#"Divided Column" = Table.TransformColumns(#"Removed Columns", {{"Index", each _ / 4, type number}}),
#"Rounded Up" = Table.TransformColumns(#"Divided Column",{{"Index", Number.RoundUp, Int64.Type}}),
#"Pivoted Column" = Table.Pivot(#"Rounded Up", List.Distinct(#"Rounded Up"[capabilitiesname]), "capabilitiesname", "capabilityvalue")
in
#"Pivoted Column"
Thanks,
thingsclump
accpet solution if this works for you.