Forum Discussion
Formula to count a row, reset if 3 values found within last 24 days, display count since reset
Here is a more complicated solution that has multiple tabs and windows across those tabs.
for this example I made the "window" 5 days to see it easier. The red highlight the 3-5day window that caused the reset and the green is the days since and 2 of the examples go back to prior tabs.
=LET(all_data,HSTACK(January:December!A1:AG10),
window, 5,
tday, DAYS(TODAY(),DATE(YEAR(TODAY()),1,1)),
data, TAKE(DROP(FILTER(all_data,TAKE(all_data,1)<>""),1),,tday),
seqA, SEQUENCE(tday),
seqB, SEQUENCE(,tday-window+1),
winMatrix, (seqA >= seqB)*(seqA <= (window-1 + seqB)),
results, (MMULT(--(data="DO"),winMatrix)>=3)*DROP(data="DO",,window-1)*(window-1 + seqB),
out,BYROW(results, LAMBDA(r, tday-MAX(r))),
out)to explain:
row 1 collects all the data across all the tabs (assumes you have January - December tabs)
row 2 is the 'window' size to look for the "DO". you will set this back to 24.
row 3 is the 'test' date to use. In this case I used today which is 86 day of the year
row 4 takes all the data from row 1 and removed the empty columns (e.g. FEB should only have 1-28 or 1-29 listed in row 1 so will remove the empty columns coming from that tab) and then removes that top line of day numbers and then only takes the columns up to the 'test' date (tday)
rows 5,6,7 just create the sliding window
row 8 does the matix multiplication to find the locations where a "DO" causes a reset and sets those places = to the day of the year
row 9 goes row by row and returns the days since the last reset event
row 10 spits out row 9