Habit Streak Formula: Why Current Streak Shows 0 Until You Check In
Build a current streak and a best streak in Google Sheets with a helper row and INDEX, and see why the current number reads 0 until today is marked.
本文目錄
You check the tracker in the morning and the current streak says 0. Yesterday you finished the habit, and so did the two days before it. The best streak next to it says 5, which is true for some week earlier in the month and not for the run you’re on.
Both numbers come from the same row of helper formulas. Current streak reads one cell of that row, the cell for the As of date. Best streak takes the largest cell in the whole row. On a day you haven’t marked yet, the cell you read is a reset, so the current streak is 0 until you check in.
The helper row, one cell per day
Here are 17 days of a “Walk 8,000 steps” habit, the same sequence the free habit tracker template ships with. An x is a done day, a dot is an empty cell, and the third line is what the helper row holds under each day:
Day 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Mark x x . x x x x x . x x x . x x x .
Streak 1 2 0 1 2 3 4 5 0 1 2 3 0 1 2 3 0
To rebuild it, put the month’s first day in B2 (2026-11-01) and the As of date in B3 (2026-11-17). Day numbers 1 to 31 go in C4:AG4, the marks in C5:AG5, and the helper in row 6. In C6, the first day:
=IF(OR(C5="x",C5=TRUE),1,0)
In D6, then filled right to AG6:
=IF(OR(D5="x",D5=TRUE),C6+1,0)
Each cell is the run length ending on that day: the cell to its left plus one if the day is marked, otherwise 0. The C5=TRUE half is there for checkboxes, which store TRUE, so the same row works with typed marks, ticked boxes, or a mix.
I’d keep this in cells rather than hide it in one array formula. When a streak looks wrong, you can read row 6 and see the day it reset. The template does it the same way, on its own Streaks sheet.
Current streak reads one cell, best streak reads all of them
First work out how many days of the month the As of date covers, in B4:
=MAX(0,MIN(B3,EOMONTH(B2,0))-B2+1)
That returns 17 here. It stops at the month’s length if B3 is later (an As of of 20 December gives 30 for November) and returns 0 if B3 is before the month starts. Then pick that day out of the helper row:
=IF(B4=0,0,INDEX(C6:AG6,1,B4))
This returns 0, because day 17 is empty. The best streak is the biggest value anywhere in the row:
=MAX(C6:AG6)
It returns 5, the run from day 4 to day 8. Mark day 17 and the helper cell under it becomes day 16’s 3 plus one: the current streak is 4, and the best stays 5.
The IF(B4=0,0,...) guard is not decoration. With As of set to 31 October, INDEX(C6:AG6,1,0) doesn’t complain. It returns 1, the first day’s value, which would show a streak that doesn’t exist.
Showing yesterday’s streak in the morning
A 0 at 8 a.m. is accurate and still discouraging. If you’d rather the dashboard show the run that is still alive before today’s check-in, take the larger of today’s cell and yesterday’s:
=IF(B4=0,0,MAX(INDEX(C6:AG6,1,B4),INDEX(C6:AG6,1,MAX(1,B4-1))))
With day 17 blank this returns 3. After you mark day 17 it returns 4, the same as the strict version. If today is marked, today’s cell is always larger than yesterday’s, and if it isn’t, today’s cell is 0, so the formula picks the right one. MAX(1,B4-1) keeps it from pointing at day 0 on the first of the month.
Label the two cells differently, “Current streak” and “Streak through yesterday”, or you’ll get the question about why they disagree.
Days you’ve marked ahead of time
The current streak ignores any marks after the As of date, because INDEX stops at B4. Best streak does not. I marked days 18 to 24 with As of still at 17 November: the current streak stayed 0, but MAX(C6:AG6) jumped to 7, a run that hasn’t happened yet. To cap the best streak at the As of date:
=IF(B4=0,0,MAX(C6:INDEX(C6:AG6,1,B4)))
That returned 5 again. If nobody pre-fills days in your sheet, the plain MAX is fine.
Which marks count
The helper formula counts a lowercase x and TRUE. A capital X counts too: I put X on day 14 and TRUE on day 15 inside the run, and the streak still read 4. Comparisons like D5="x" aren’t case-sensitive in Google Sheets, and LibreOffice treated them the same way.
Spaces are different. An x with a trailing space, or x with a leading one, doesn’t equal "x". With a trailing space on day 15, the streak fell from 4 to 2, and nothing in the sheet flagged it. If your marks come from pasted or imported data, wrap the cell in TRIM:
=IF(OR(TRIM(D5)="x",D5=TRUE),C6+1,0)
That brought the 4 back. TRIM not working covers the case where the space is a non-breaking one and TRIM leaves it alone.
A streak counts consecutive days, so it can’t tell you how many days you hit in total. For that count, including with checkboxes, see How to count checked checkboxes in Google Sheets. The template pairs this streak with a done count and a “Still possible” goal check. Its streak formulas are the two above: INDEX(Streaks!C5:AG5,$N$2) for current and MAX(Streaks!C5:AG5) for best.
These formulas use nothing but IF, OR, INDEX, MAX 與 EOMONTH, so they should carry over to Excel as they are. I ran this page’s formulas in Google Sheets and LibreOffice, not in Excel, though the template’s streak columns were checked in Excel for Mac.