Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Syndicate_Admin
Administrator
Administrator

Grouping by consecutive data in column

Good afternoon everyone, I have some speed test data, these can be successful or failed. I need to set up consecutive failed test groups. This is in order to find the start date and end date of each of the groups. At the moment this is my data

csmonroy_0-1704393721899.png


What I'm hoping for as a next step is to get to this: (Create the ID Group column)

csmonroy_2-1704393850776.png

And as a final result I need this:

csmonroy_3-1704394146376.png

which is the product of the following analysis:

csmonroy_4-1704394193369.png

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

Consider the example table...

jgeddes_0-1704398419419.png

You can end up with the following...

jgeddes_1-1704398482922.png

Using the code...

let
    Source = 
    Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc67CsAgDIXhV5HMgiaN160tdO4uvv9r1KlwzHAyffxkDOKgQaKoY+5JydN53eu+a0zTbyD94FkTCzKAw4ICQC2o8EOyoDlI5E1IjxESxQKGQrVAADSa8wM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Code = _t, Result = _t, Index = _t]),
    #"Changed Type" = 
    Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"Code", type text}, {"Result", type text}}),
    #"Grouped Rows" = 
    Table.Group(#"Changed Type", {"Result"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"Records", each _, type table [Date=nullable datetime, Code=nullable text, Result=nullable text]}},GroupKind.Local),
    #"Group Failed" = 
    Table.AddIndexColumn(Table.SelectRows(#"Grouped Rows", each [Result] = "F" and [Count] <> 1), "Group", 1, 1),
    #"Removed Columns" =
    Table.RemoveColumns(#"Group Failed",{"Result", "Count"}),
    #"Expanded Records" = 
    Table.ExpandTableColumn(#"Removed Columns", "Records", {"Date", "Code", "Result", "Index"}, {"Date", "Code", "Result", "Index"}),
    #"Non Consecutive" = 
    Table.SelectRows(#"Grouped Rows", each [Result] <> "F" or [Count] = 1),
    #"Removed Columns1" = 
    Table.RemoveColumns(#"Non Consecutive",{"Result", "Count"}),
    #"Expanded Records1" = 
    Table.ExpandTableColumn(#"Removed Columns1", "Records", {"Date", "Code", "Result", "Index"}, {"Date", "Code", "Result", "Index"}),
    #"Combine Tables" = 
    Table.Combine({#"Expanded Records1", #"Expanded Records"}),
    #"Sorted Rows" = 
    Table.Sort(#"Combine Tables",{{"Index", Order.Ascending}})
in
    #"Sorted Rows"

 

The key is the GroupKind.Local in the Table.Group step.

Hopefully this helps. 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

1 REPLY 1
jgeddes
Super User
Super User

Consider the example table...

jgeddes_0-1704398419419.png

You can end up with the following...

jgeddes_1-1704398482922.png

Using the code...

let
    Source = 
    Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc67CsAgDIXhV5HMgiaN160tdO4uvv9r1KlwzHAyffxkDOKgQaKoY+5JydN53eu+a0zTbyD94FkTCzKAw4ICQC2o8EOyoDlI5E1IjxESxQKGQrVAADSa8wM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Code = _t, Result = _t, Index = _t]),
    #"Changed Type" = 
    Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"Code", type text}, {"Result", type text}}),
    #"Grouped Rows" = 
    Table.Group(#"Changed Type", {"Result"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"Records", each _, type table [Date=nullable datetime, Code=nullable text, Result=nullable text]}},GroupKind.Local),
    #"Group Failed" = 
    Table.AddIndexColumn(Table.SelectRows(#"Grouped Rows", each [Result] = "F" and [Count] <> 1), "Group", 1, 1),
    #"Removed Columns" =
    Table.RemoveColumns(#"Group Failed",{"Result", "Count"}),
    #"Expanded Records" = 
    Table.ExpandTableColumn(#"Removed Columns", "Records", {"Date", "Code", "Result", "Index"}, {"Date", "Code", "Result", "Index"}),
    #"Non Consecutive" = 
    Table.SelectRows(#"Grouped Rows", each [Result] <> "F" or [Count] = 1),
    #"Removed Columns1" = 
    Table.RemoveColumns(#"Non Consecutive",{"Result", "Count"}),
    #"Expanded Records1" = 
    Table.ExpandTableColumn(#"Removed Columns1", "Records", {"Date", "Code", "Result", "Index"}, {"Date", "Code", "Result", "Index"}),
    #"Combine Tables" = 
    Table.Combine({#"Expanded Records1", #"Expanded Records"}),
    #"Sorted Rows" = 
    Table.Sort(#"Combine Tables",{{"Index", Order.Ascending}})
in
    #"Sorted Rows"

 

The key is the GroupKind.Local in the Table.Group step.

Hopefully this helps. 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.