Forum Discussion
Sedos101
3 years agoHelper I
Grouping
Hi Everyone I am trying to group a set of rows based on reocurring row values. Essentially I have a Haul Truck that I want to define each cycle it does from its haul cycle state. The start...
- 3 years ago
Hi Sedos101 ,
please check the solution in the file attached.
ImkeF
3 years agoCommunity Champion
Hi Sedos101 ,
you can try this Power Query solution:
let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"i45W8slPTMnMS1eK1YlWcivNyalUAImkphApEFySX1CQmkJAyKU0twBmCS52SFFiWWoOkKfgmltQUolTDGY8aSJ4vYmwhnhvEOG0WAA=",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [#"Cycle State" = _t]
),
#"Changed Type" = Table.TransformColumnTypes(Source, {{"Cycle State", type text}}),
#"Grouped Rows" = Table.Group(
#"Changed Type",
{"Cycle State"},
{{"Cycle", each _, type table [Cycle State = nullable text]}},
0,
(x, y) => Number.From(y[Cycle State] = "Loading") // this is where the magic happens
),
#"Removed Columns" = Table.RemoveColumns(#"Grouped Rows", {"Cycle State"}),
#"Added Index" = Table.AddIndexColumn(#"Removed Columns", "Index", 1, 1, Int64.Type),
#"Expanded Cycle" = Table.ExpandTableColumn(
#"Added Index",
"Cycle",
{"Cycle State"},
{"Cycle State.1"}
)
in
#"Expanded Cycle"
It is based on using the 5th parameter of the Table.Group-function like described here:
Table.Group: Exploring the 5th element in Power BI and Power Query – The BIccountant
It will create a new group everytime "Loading" occurs. Then you can add an index column for the sequence-numbers before expanding the original data.