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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Johannes_Swarts
Advocate I
Advocate I

Counting rows for event sequences

Hello,

 

I have data that looks like this:

 

Johannes_Swarts_0-1730030518248.png

 

Data consists of date/time (down to millisecond), a work item ID, and events within the work item.  Colors designate different types of events - top few events are masked for confidentiality reasons.

 

What I'm trying to do is to collapse the work item into a time sequence of single events representing either 1) single event occurrences, or 2) blocks of the same event.

 

Goal:

time stamp

work item ID

event type

count of event types

 

For example, see the orange event sequence (Current Layer Changed).  Data shows 6 different occurrences in sequence.  I'd like to see a single row - timestamp    workitem_id      event_function     6

 

There are slicers enabled for user, project, date (day).

My knowledge of Power BI is at the beginner/intermediate level.  I have a pretty good working knowledge of DAX.

 

Thanks in advance!

 

Hans

4 REPLIES 4
danextian
Super User
Super User

Hi @Johannes_Swarts ,

 

If you're looking for something like the screenshot below, you can make use of an extra parameter when grouping a table in Power Query which groups rows by sequence. In a sequence of A-B-C-A-A-B-C-C-C, A-A and C-C-C will each own group, the rest will each have their own as well. After grouping you can then add an index column to identify the groups.

danextian_1-1730096478284.png

 

danextian_0-1730096260619.png

Here's a sample code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ddJJCoAwEETRq0jWQnoyRncOtwje/xoquJL89YOuoujWktSskk0sBo1VljSmLV3jH1QIlMAJgqAQzA/sPagEC4C9dY8eGIETTFDXCoVXOvXWPTvgtK4bAa3rE4R7IaC6TusGfUl86143", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Timestamp = _t, Event = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Timestamp", type datetime}, {"Event", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Event"}, {{"Grouped", each _, type table [Timestamp=nullable datetime, Event=nullable text]}}, GroupKind.Local),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "RowCount", each Table.RowCount([Grouped])),
    #"Expanded Grouped" = Table.ExpandTableColumn(#"Added Custom", "Grouped", {"Timestamp"}, {"Timestamp"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Expanded Grouped",{"Timestamp", "Event", "Index", "RowCount"})
in
    #"Reordered Columns"

 

You may also try this approach that uses DAX instead:

https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Cthulhu/m-p/509739#M211 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Selva-Salimi
Super User
Super User

Hi @Johannes_Swarts 

 

you just need to use a table in visualisation pane

SelvaSalimi_0-1730032754513.png

 

add each of these column in columns part:

SelvaSalimi_1-1730032791256.png

 

and then select first/last or max/min for timestamp, work item_id and first event function. add first event function twice to the columns part (drag and drop). select count for the second one. 

SelvaSalimi_2-1730032979204.png

 

 

If this post helps, then I would appreciate a thumbs up  and mark it as the solution to help the other members find it more quickly.

Hello Selva-Salimi,

 

Thanks for the reply!  Simple solution, which I like.

 

However, not exactly what I was looking for...  🙂

 

Johannes_Swarts_0-1730034449497.png

Yous solution in table at lower right, orginal table at upper left.

 

Your solution gives the total count of each event type in the work item, along with the first date/timestamp.  I'm looking for a more detailed view that shows the event type count and first date/time for each GROUP of same events in the work item.  I expect to see, taking Extents Changed as an example:

 

date/time 1     Extents Changed     count A

date/time 2     Extents Changed     count B

date/time 3     <some other event>     count C

date/time 4     Extents Changed     count D

etc

:

:

 Maybe another column trick?

Thanks,

 

Hans

 

 

 

Oops - in my example above, pretend the first Events Changed in some other event.

Sorry!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.