Count 0s and 1s in streak - Habit Tracker

gtcpenn

New Member
Joined
Jan 20, 2022
Messages
3
Office Version
  1. 365
Platform
  1. MacOS
Hi all,

I am building a habit tracker at the moment and I wanted to find a formula to count the streak (current consecutive number of successes) of following the habit. I also want to not count certain letters ("w", "o", and "h") which should not break the streak. 1s are days which I achieved my goal, 0s are when I have failed.

In short, what I want to do is have the current streak showing in B2:B7 per habit for the whole year

Have been struggling with this for days now. What I'm looking for is a formula if possible!

Thanks so much!!

George
 

Attachments

  • Screenshot 2022-01-20 at 15.45.51.png
    Screenshot 2022-01-20 at 15.45.51.png
    51.1 KB · Views: 20

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Welcome to the MrExcel forum!

How about:

Book2
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAG
1HabitCurrent Streak
212345678910111213141516171819202122232425262728293031
3Workout1wwh1010wwo0110wwooo1wwww
4Cold Shower5wwh0011ww01111wwooo1wwww
5Meditation1wwh0010ww11001ww1101wwww
6Vegan011111o01111111111110
7Alcohol free1ww1011ww11110ww11101wwww
8In Bed by 003w01011ww11101wwo0111ww
Sheet4
Cell Formulas
RangeFormula
B3:B8B3=COUNTIF(INDEX(C3:AG3,XMATCH(0,C3:AG3,1,-1)):AG3,1)
 
Upvote 0
Hi There,

Thanks for the response, and for the welcome!

Somehow when I put this into the file I end up with 0 as a streak - not sure why? Other than the range, is there something I need to adjust?

Cheers,

George
 
Upvote 0
Well, that's odd! I had a parameter wrong in the XMATCH function, I don't know why it worked at all on my test sheet. I also added a tweak so that it would work if the row has no 0 values. Give this a try:

Book2
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAG
1HabitCurrent Streak
212345678910111213141516171819202122232425262728293031
3Workout1wwh1010wwo0110wwooo1wwww
4Cold Shower5wwh0011ww01111wwooo1wwww
5Meditation1wwh0010ww11001ww1101wwww
6Vegan011111o01111111111110
7Alcohol free1ww1011ww11110ww11101wwww
8In Bed by 003w01011ww11101wwo0111ww
Sheet4
Cell Formulas
RangeFormula
B3:B8B3=COUNTIF(INDEX(C3:AG3,IFERROR(XMATCH(0,C3:AG3,0,-1),1)):AG3,1)
 
Upvote 0
Thanks so much for taking the time on this - you are amazing! This works well with the ws and os, but for it doesn't end the streak for me when I enter a zero anymore.
 
Upvote 0
I'm not sure what to tell you, a 0 restarts the streak when I test. Are there some cells formatted as text? There's an example in my last post even (row 6). If you could post an example, I'll take a look. I used a tool called XL2BB (see my signature) which is very easy to use and see exactly what's going on. But even a picture like you did before might help.
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,614
Members
449,091
Latest member
gaurav_7829

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top