Forum Discussion
Change in Table field
- 1 year ago
Hi aqeel_shaikh, two more solutions:
Output
v1
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAwMTOwtNA1NDBQ0lEyMzbUgzAMQHSsDroCSxNTiAJjM+wKjE0MoCpwmGBoZG4OUWAIURELAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PNR = _t, Price = _t, #"Qty Break" = _t]), ChangedType = Table.TransformColumnTypes(Source,{{"Price", Currency.Type}, {"Qty Break", type number}}, "en-US"), Grouped = Table.Group(ChangedType, {"PNR"}, {{"All", each [ AddedIndex = Table.AddIndexColumn(_, "Index", 1, 1, Int64.Type), UnpivotedOtherColumns = Table.UnpivotOtherColumns(AddedIndex, {"PNR", "Index"}, "Attribute", "Value"), MergedColumns = Table.CombineColumns(Table.TransformColumnTypes(UnpivotedOtherColumns, {{"Index", type text}}, "sk-SK"),{"Attribute", "Index"}, Combiner.CombineTextByDelimiter(" ", QuoteStyle.None), "Attribute"), PivotedColumn = Table.Pivot(MergedColumns, List.Distinct(MergedColumns[Attribute]), "Attribute", "Value") ][PivotedColumn], type table}}), Combined = Table.Combine(Grouped[All]) in Combinedv2
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAwMTOwtNA1NDBQ0lEyMzbUgzAMQHSsDroCSxNTiAJjM+wKjE0MoCpwmGBoZG4OUWAIURELAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PNR = _t, Price = _t, #"Qty Break" = _t]), ChangedType = Table.TransformColumnTypes(Source,{{"Price", Currency.Type}, {"Qty Break", type number}}, "en-US"), GroupedRows = Table.Group(ChangedType, {"PNR"}, {{"All", each List.Accumulate( {0..Table.RowCount(_)-1}, Table.FirstN(Table.RemoveColumns(_, {"Price", "Qty Break"}), 1), (s,c)=> Table.AddColumn(Table.AddColumn(s, "Price " & Text.From(c+1), (x)=> [Price]{c}, Currency.Type), "Qty Break " & Text.From(c+1), (y)=> [Qty Break]{c}, type number)), type table}}), Combined = Table.Combine(GroupedRows[All]) in Combined
This is step by step solution
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAwMTOwtNA1NDBQ0lFSMDM21IOyDECMWB0MJZYmplAlxmY4lBibGMDU4DLF0MjcHKrEEKImFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PNR = _t, Price = _t, #"Qty Break" = _t]),
Custom1 = Table.Group(Source, "PNR", {"S1", each _}),
#"Added Custom" = Table.AddColumn(Custom1, "Custom", each Table.RemoveColumns([S1],"PNR")),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Table.ToRows([Custom])),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.2", each List.Combine([Custom.1])),
Custom2 = Table.SplitColumn(#"Added Custom2", "Custom.2", each _)
in
Custom2