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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.