Reputation: 191
I am creating a spreadsheet to track my habits through the coming year, and I want to be able to show both a simple count, and also a current streak for each habit. I've already searched and found one answer for counting a streak, but this answer does not work with a live tracker (increasing the end column by one each day), and also requires there to be no blank fields (1 or 0 entry).
=COUNTA(S$2:S$74)-MATCH(2, 1/(S2:S$74=0), 1)
If I switch the above from =0 to ="" in the match, it breaks pretty spectacularly, and in any case it fails completely for a range that includes 366 days, but the current day is <366. I would be tracking "current day" by a habit row labeled "logging" that I would populate each day, whether any other habits were logged or not. Is this something possible with formulas?
Using the suggestions I got to concat 1's and 0's to a string, I then got a successful streak formula using
=IFERROR((LEN(NG3)-SEARCH("0[^0]*$",NG3)),LEN(NG3))
Where NG is the column the concatenations exist in, and row 3 is the first row of data. I then basically duplicated my calendar to allow for non-binary logging (converting any blank or 0 entry to a 0, all other entries to a 1), and contingent on the "logged" row being populated so that unlogged days are blank fields. Works like a charm now.
Upvotes: 1
Views: 229
Reputation: 8904
My interpretation of the algorithm for this:
In formula put the following:
=MAX(LEN(SPLIT(B1,"0")))
This will convert formula into an ArrayFormula.
(You need to do this, because if you just entered
=SPLIT(B1)
in C1, it would generate a range of columns, one per array entry, filling C1, D1, E1 etc...).
Here are the formulae:
Here is the output:
Sample spreadsheet in GoogleDocs
You may be able to upload/download/convert it between Googledocs and LibreOffice.
Have not used that spreadsheet solution.
But most are pretty similar these days.
Upvotes: 1