Search code examples
google-sheetsgoogle-sheets-formula

ARRAYFORMULA in GOOGLE SHEETS


I am trying to count sequentially depends on the value using ArrayFormula to avoid manually dragging the column, I want to autofill everytime I add a value in Column A

in Column B - the ArrayFormula does not work

=ARRAYFORMULA(IF(I$1:I<>"", COUNTIF(I$1:I1, I1:I), ""))

in Column C - I tried to do it using

=COUNTIF(I$1:I1, I1:I)

A B C
A1 1 1
A1 1 2
A1 1 3
B1 0 1
B1 0 2
A2 0 1
A2 0 2

I tried to replicate the result in Column C using ArrayFormula but i couldn't do it.

Thank you.


Solution

  • Use the following formula in row 1 of an empty column:

    =ARRAYFORMULA(IF(I:I="",,COUNTIFS(I:I,I:I,ROW(I:I),"<="&ROW(I:I))))
    

    You could also do it using MAP:

    =MAP(I:I,LAMBDA(_,IF(_="",,COUNTIF(I1:_,_))))