Search code examples
arraysgoogle-sheetsindexingcount

Use an array to get the count for x


rows    A     B
1       1   Joe
2       2   Bill
3       3   Pete
4       4   Victor
5       5   Don
6       6   Victor
7       7   Bob

=ArrayFormula(LOOKUP(2,1/(b1:b7="Victor"),(a1:a7)))

This will output 6 because I have numbered the rows in A. How do I add count() into the array so it will actually count the rows up to (the last) Victor?


Solution

  • To get the number of rows in column B up to the last occurrence of "Victor", you can use the following formula:

    =ROWS(B1:XLOOKUP("Victor",B:B,B:B,,,-1))
    

    enter image description here