Count most recent consecutive occurrences of text value in a row

pawneeranger

New Member
Joined
Jul 27, 2022
Messages
2
I am keeping a progress tracker and want to know how many weeks in a row that something has been "off track" but only if it has been off track in the most recent week. For instance in the table below, I want to be able to ask Excel, "IF a project is off track in Week 4, how many weeks IN A ROW has it been off track?" (The answer being 2 - it has been off track for two consecutive weeks.)


Week 1Week 2Week 3Week 4
Off TrackOn TrackOff TrackOff Track
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Please specify which Office version you do use

For Office 365 or Office 2021 try
Excel Formula:
=LET(wStat,B2:E2,Array,ROW(INDIRECT("1:"&COLUMNS(wStat))),MAX(IF(RIGHT(TEXTJOIN("",TRUE,IF(wStat="Off Track",1,0)),Array)=REPT("1",Array),Array,0)))
Instead of B2:E2 specify the range with the week status

For older version, try
Excel Formula:
=MAX(IF(RIGHT(TEXTJOIN("",TRUE,IF(B2:E2="Off Track",1,0)),ROW(INDIRECT("1:" &COLUMNS(B2:E2))))=REPT("1",ROW(1:4)),ROW(INDIRECT("1:"&COLUMNS(B2:E2))),0))
Again, replace those B2:E2 with the range of your week status
 
Upvote 0
Does this do what you want?

22 07 28.xlsm
ABCDEFGHIJ
1ResultWeek 1Week 2Week 3Week 4Week 5Week 6Week 7Week 8
22Off TrackOn TrackOff TrackOff Track
34Off TrackOff TrackOff TrackOff Track
40On TrackOn TrackOn TrackOn Track
51Off TrackOn TrackOn TrackOff Track
60Off TrackOff TrackOff TrackOn Track
Off Track
Cell Formulas
RangeFormula
A2:A6A2=COUNTA(C2:J2)-IFERROR(AGGREGATE(14,6,(COLUMN(C2:J2)-COLUMN(C2)+1)/(C2:J2="On Track"),1),0)


For older version, try
Would only be for one older version - TEXTJOIN only appeared in Excel 2019. :)
 
Upvote 0
TextJoin is available in Office 2016, for sure is not available in Office 2010; don't know what about Office 2013

Your formula is quite smart, I only wonder why you didn't publish it 12 hours ago, I would have been saving 15 minutes of my time
 
Upvote 0
TextJoin is available in Office 2016,
Hmm, I was just going on the Microsoft help re TEXTJOIN

1659015265580.png


Could be part of an Add-In for some people?
 
Upvote 0
Unfortunately I’m just using Sheets (work computer - max - don’t even get me started) but I will give all of these a shot!
 
Upvote 0
I did not expect this hot debate about TextJoin...
And anyway two versions is much more that only one ;)
 
Upvote 0

Forum statistics

Threads
1,223,336
Messages
6,171,524
Members
452,409
Latest member
brychu

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