Google Sheets – ArrayFormula for Conditional Consequential Sum-Up

formulasgoogle sheetsgoogle-sheets-arrayformula

I have a table which looks like this:

1

And formula in cell B3: =IF(A3>5, B2, B2+1) and on every next row a corresponding variation of this formula.

I would like to know how to create ArrayFormula variant of this formula:

=IF(A3>5, B2, B2+1)

spreadsheet sample here

Best Answer

=ArrayFormula({"Result";IF(A2:A="","",COUNTIFS(ROW(A2:A),"<="&ROW(A2:A),A2:A,"<=5"))})