Forum Discussion
Convert multiple rows into one row with sorted columns
- 5 years ago
Here's one way to do it in the query editor. To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below. You need to select your first two columns then choose Group By and accept the default Count option. You then need to modify the code in the Formula Bar to match the below, and then split the column by the "_" to get your result.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUaoE4kQgNlaK1UGIJAGxEVjECMiqAOJkIDYEixhDeSlAbIIikgrEFigiaUBsBhYxAbLKgDgdbpcp1J4MiF2xAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Number = _t, #"Value 1" = _t, #"Value 2" = _t, Amount = _t]), #"Grouped Rows" = Table.Group(Source, {"Number", "Value 1"}, {{"Value 2", each Text.Combine([Value 2], "_")}}), #"Split Column by Delimiter" = Table.SplitColumn(#"Grouped Rows", "Value 2", Splitter.SplitTextByDelimiter("_", QuoteStyle.Csv), {"Values.1", "Values.2", "Values.3"}) in #"Split Column by Delimiter"Pat
Here's one way to do it in the query editor. To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below. You need to select your first two columns then choose Group By and accept the default Count option. You then need to modify the code in the Formula Bar to match the below, and then split the column by the "_" to get your result.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUaoE4kQgNlaK1UGIJAGxEVjECMiqAOJkIDYEixhDeSlAbIIikgrEFigiaUBsBhYxAbLKgDgdbpcp1J4MiF2xAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Number = _t, #"Value 1" = _t, #"Value 2" = _t, Amount = _t]),
#"Grouped Rows" = Table.Group(Source, {"Number", "Value 1"}, {{"Value 2", each Text.Combine([Value 2], "_")}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Grouped Rows", "Value 2", Splitter.SplitTextByDelimiter("_", QuoteStyle.Csv), {"Values.1", "Values.2", "Values.3"})
in
#"Split Column by Delimiter"
Pat
- F54478955 years agoNew Member
Perfect, thank you. 👍