Sometimes it takes a little extra motivation to keep up with your routines and meet your goals. Knowing you are on a streak, and avoiding breaking it, can be just the push you need!

Calculating streaks can be quite complicated in Coda, requiring some fancy formulas. Lucky for you there is a Pack that makes it simple:

Below is a very simple table, which logs whether you’ve worked out on a given day. The Streak column uses the Pack to calculate how long the streak was on each day.

Try it! Add rows and toggle checkboxes to see it recalculate the streaks.

Workouts

Workouts

1

Date

Complete

Streak

Date

Complete

Streak

1

1/1/2023

1

2

1/2/2023

2

3

1/3/2023

3

4

1/4/2023

0

5

1/5/2023

1

6

1/6/2023

2

7

1/9/2023

1

8

1/10/2023

2

9

1/11/2023

3

There are no rows in this table

You’re on a

3

day streak.

Keep it up!

Setup

Select the columns to used to calculate the streak.

The first must be a Date column, representing the date of the entry.

The second must be a Checkbox column, indicating if the goal was met on that date. You can use a formula to calculate the value of this checkbox column, if it is dependent of various data points in the row.

Add a new Number column to hold the streak value.

Add a formula to that column, with the following format:
Streaks(Table.Date, Table.Checkbox).Nth(Table.Find(thisRow))
Replace Table with the name of the table, Datewith the name of the Date column, and Checkboxwith the name of the checkbox column.
For example, here’s the formula used in the demo table above:

That’s it! You should now have a streak value for each row in your table.

How it works

Unlike most formulas which work on a single row at a time, calculating a streak requires looking at all of the previous rows. To improve performance, the formula calculates all of the streak values for the entire table in one go.

For example, here is the result of calling the Streaks() formula on the demo table above.

Streaks(Workouts.Date, Workouts.Complete) =>

123012123

Notice how you pass in the entire column of dates and the entire column of checkboxes, and then get back an entire column of streaks.

Once you have the total set of streaks, it’s just a matter of displaying the right value for each row. Table.Find(thisRow) gets the row number of the current row, and then .Nth() pulls out the corresponding streak at that index.

Advanced options

What happens if you get sick and miss a few days? Should that break the streak? Well, the answer may depend on how strict you want to be with yourself, but you can use the Streaks() formula either way!

To allow for gaps in the log without breaking the streak, set the advanced option allowGaps.