How to compute current 'streak' of event dates?

Hello, I would like to implement a “Streak” feature in my app. The app lets users record time entries, and I’d like to be able show them that they’ve recorded an entry for 5 days in a row for example. I have a table for “Entries” with a Date column. The actual computed streak would live in another “Metrics” table — each entry type is associated with a “Metric” row.

I know that once I have the first day of the streak, I can use a subtraction to get a duration from today and figure it out from there. But I don’t know how I’d compute the first day of the streak.

I can think of how code for it might work; start with today and “walk back” a day at a time until we find the first day where there isn’t an event. Sound tricky to implement this in a formula expression though…

Any help would be appreciated!

Solved Solved
0 3 410
1 ACCEPTED SOLUTION

Add a column to the “Entries” Table, [Last Entry], with expression:

MAXROW( "Entries" , "_RowNumber" , [date] < [_THISROW].[date] )

Add another column to “Entries”, [Streak Count], with expression:

IF(
  [Last Entry].[date] = [date]-1 ,
  [Last Entry].[Streak Count] + 1 ,
  1
)

View solution in original post

3 REPLIES 3