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 411
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

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
)

Powerful! Thank you!

Hello,

Hope you are doing great! It is showing this error:

Arithmetic expression '([Last Entry].[Streak Count]+1)' has inputs of an invalid type 'Unknown'