Search code examples
google-sheetsgoogle-sheets-formula

How to Count cells since the last filled cell in a column, and repeat for each time a cell is filled


I have a tracking spreadsheet to track dry streak calcs for certain drops from a boss in a video game. I want to be able to easily see my dry streaks by having the sheet count the amount if boss kills since the last drop.

I have the following:

=IF(B2="",COUNTBLANK(B2:INDEX($B2:B,MATCH(FALSE,($B2:B=""),0))),"")+1

where column A is the boss kill count, and column B is filled if a drop is received.

the above formula works to an extent of what i want, but the order is upside down. I'd also like it to only show the "count since last drop" when a cell in column B is filled., rather than every cell showing it.

Example sheet


Solution

  • If column A is a sequence of numbers as depicted in the sample you can use formula 1 and formula 2 is stand-alone just based on column B. Please test them out.

    formula 1:

    =let(a,filter(A2:A,B2:B="drop"),byrow(A2:A,lambda(z,IF(offset(z,,1)="drop",z-xlookup(offset(z,-1,),a,a,,-1),))))
    

    formula 2:

    =let(a,filter(row(B:B)-1,B:B="drop"),byrow(B2:B,lambda(z,IF(z="drop",row(z)-1-xlookup(row(offset(z,-2,)),a,a,,-1),))))
    

    enter image description here