Counting backwards in a row until a certain number is met

furness121

New Member
Joined
Jan 24, 2024
Messages
5
Office Version
  1. 2021
Platform
  1. Windows
I have an attendance streak tracker, I want it to tell me the current number of streaks for this term. (I have already calculated the highest overall number of streaks in the term and year using max & frequency).

I need it to look at the last number entered and if it is 10, count backwards until it reaches another number less than 0 in the row and then stop, if it has a number less than 10 at the start it will enter 0 as they have no streak this week.

e.g in the example data the first row should say 40 as there are 4, 10 since the last number less than 10 and the second should say 0 as that number is less than 10.

Attendance data current.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAK
1Autumn termSpring termSummer term
2NameRegWeek 8Week 9Week 10Week 11Week 12Week 13Week 14Week 15Week 16Week 17Week 18Week 19Week 20Week 21Week 22Week 23Week 24Week 25Week 26Week 27Week 28Week 29Week 30Week 31Week 32Week 33Week 34Week 35Week 36Week 37Week 38Week 39Week 40Current streak
3Week number123456789101112131415161718192021222324252627282930313233
4Student 110010101010010101010101010101010101010101041010101040
5Student 210100010101010100101010101010101010101010106101060
6Student 3
7Student 4
8Student 5
9Student 6
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C4:AI9Cell Value=10textNO
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I'm not sure if this is going to always work, it requires no intervening blank cells. But, it seems to work here:

UPDATE after I posted: This is sad. The TAKE, SCAN, and LAMBDA functions are only available on 365 and Excel on the web:

Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel for the web
So, unless you can do this on the web, the formula will be hard to build.


Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAK
1Autumn termSpring termSummer term
2NameRegWeek 8Week 9Week 10Week 11Week 12Week 13Week 14Week 15Week 16Week 17Week 18Week 19Week 20Week 21Week 22Week 23Week 24Week 25Week 26Week 27Week 28Week 29Week 30Week 31Week 32Week 33Week 34Week 35Week 36Week 37Week 38Week 39Week 40Current streak
3Week number123456789101112131415161718192021222324252627282930313233
4Student 110010101010010101010101010101010101010101041010101040
5Student 210100010101010100101010101010101010101010106101060
6Student 3
Sheet2
Cell Formulas
RangeFormula
AK4:AK5AK4=TAKE(SCAN(0,FILTER(C4:AI4,C4:AI4<>"",""),LAMBDA(a,b,IF(b=10,a+b,0))),,-1)
 
Last edited:
Upvote 0
The following formula returns the expected results for the posted dataset:
Excel Formula:
=10*(LOOKUP(2^1023,C4:AI4,COLUMN(C4:AI4))-LOOKUP(2^1023,1/(C4:AI4<>10)/(C4:AI4<>""),COLUMN(C4:AI4)))
 
Upvote 0
The following formula returns the expected results for the posted dataset:
Excel Formula:
=10*(LOOKUP(2^1023,C4:AI4,COLUMN(C4:AI4))-LOOKUP(2^1023,1/(C4:AI4<>10)/(C4:AI4<>""),COLUMN(C4:AI4)))
Pretty neat @Tetra201 ! I'm happy someone was able to post a solution for the OP's version.
Best Wishes!
 
Upvote 0
Here's one that works using functions available to Excel 2021:

Excel Formula:
=MAX(0,SUM(XLOOKUP({10,9},C4:AI4,COLUMN(C4:AI4),COLUMN(B4),-1,-1)*{10,-10}))
 
Upvote 0

Forum statistics

Threads
1,223,262
Messages
6,171,080
Members
452,377
Latest member
bradfordsam

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