Forum Discussion
Anonymous
6 years agoNot applicable
Sequence by multiple columns
I need to be able to sequence my data using the current sequence - but totaling the "QuantityToBuild" column by grouping by the "Component" Column. So in otherwords I would need sequence 1 and 2...
Greg_Deckler
Community Champion
6 years agoSeems like you want to do a Group By on Component in Power Query. Then add a new Index column starting from 1.
Greg_Deckler
Community Champion
6 years agoLike this. Only thing I don't understand is the logic of when to group and when not to group.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZA9D8IgEIb/imE28e6AFhzVxcXE6NY4+MFgYls1dPDfez0S61BbFw6OJ8/xUhRqFx5NqM5BTdU6hnLTlKfw5MOyLu91FarI+21zrOI1vvb1orneLtxZHWNQh2mhkA+YO14JSQoZXu0McUZAMIE5gJAkpO9IROontWhy4JJpHHK2bXTUOW3WD1oB9TiYpdk4PjvntjPOpuKHArnEmA618MMqHodfv5S5fhLb/9EI7bWXR3r4QUoag218bywNxJcELM3HpTpJ6Q+pSVL/keo+6eEN", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}, {"(blank).4", type text}}),
#"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
#"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Sequence", Int64.Type}, {"ItemNumber", Int64.Type}, {"Component", Int64.Type}, {"QuantityToBuild", Int64.Type}, {"Date", type datetime}}),
#"Grouped Rows" = Table.Group(#"Changed Type1", {"Component"}, {{"QuantityToBuild", each List.Sum([QuantityToBuild]), type number}, {"Date", each List.Max([Date]), type datetime}}),
#"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1)
in
#"Added Index"
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZA9D8IgEIb/imE28e6AFhzVxcXE6NY4+MFgYls1dPDfez0S61BbFw6OJ8/xUhRqFx5NqM5BTdU6hnLTlKfw5MOyLu91FarI+21zrOI1vvb1orneLtxZHWNQh2mhkA+YO14JSQoZXu0McUZAMIE5gJAkpO9IROontWhy4JJpHHK2bXTUOW3WD1oB9TiYpdk4PjvntjPOpuKHArnEmA618MMqHodfv5S5fhLb/9EI7bWXR3r4QUoag218bywNxJcELM3HpTpJ6Q+pSVL/keo+6eEN", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}, {"(blank).4", type text}}),
#"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
#"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Sequence", Int64.Type}, {"ItemNumber", Int64.Type}, {"Component", Int64.Type}, {"QuantityToBuild", Int64.Type}, {"Date", type datetime}}),
#"Grouped Rows" = Table.Group(#"Changed Type1", {"Component"}, {{"QuantityToBuild", each List.Sum([QuantityToBuild]), type number}, {"Date", each List.Max([Date]), type datetime}}),
#"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1)
in
#"Added Index"