Forum Discussion
Pivot issue
- 1 year ago
Hi naninamu, I'm not sure who is LDufour, but you wanted to reply me probably 😉
updated code:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCs4sSVVwVNJRSkxUitXBw09KQuUnJ+PmO6Hpd0LTTwwf2TxnNHli+KmpqPy0NATfBcgvL0flI9vnguZ+bHyQ/lgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [SITE = _t, CODE = _t]), Transformed = [ a = Table.Group(Source, {"SITE"}, {{"T", each {_{0}[SITE]} & [CODE] }}, GroupKind.Local)[T], b = let max = List.Max(List.Transform(a, List.Count)) in Table.FromRows(List.Transform(a, each _ & List.Repeat({null}, max - List.Count(_)))), c = Table.ColumnNames(b), d = Table.RenameColumns(b, List.Zip({ c, {"SITE"} & List.Transform(List.Skip(List.Positions(c)), each "CODE " & Text.From(_)) })) ][d] in Transformed
Thank you so much ZhangKun - I never would have come up with that! I didn't realise it would be so complicated.
I have tested it on my set of test data by changing the source, and it's working well.
I'm now trying to use it on my set of real data - it already has numerous transformation steps applied, and currently I can't get it to work.
I assume I paste yours in from the #"Changed Type step, and adjust the names of the 2 columns? It's also saying it doesn't recognise what "Rows" is, but I'm unsure if I should be changing or leaving that.
Many thanks once again!
- ZhangKun1 year agoSuper User
maybe you can provide more complete information, especially the name of the columns that need to be processed.