I think this answers your question:
=ArrayFormula(if(len(A2:A), countif(if(A2:D="inbox", row(A2:A)), row(A2:A)),))

The explanation is not very obvious, but here it goes:
ArrayFormula(if(something))
: the array formula will run the if statement for each row:
if(len(A2:A), something, )
: will check if the first value of each row (A
cell) is not empty, if it has any value, run the formula, if not, then don't run (notice the comma in the end, before the closing bracket , )
. A possible alternative is: if(not(isblank(A2:A)), something, )
countif( something )
: will count the number of occurrences according to a condition.
if(A2:D="inbox", row(A2:D))
- here comes the interesting part, because this formula will assign the value of the row it is in, if it finds any occurrence of the text "inbox" in it. An example is possible to see if we removed the countif()
from the formula, the result would be:
As it is possible to see, each value that was part of that if(A2:D="inbox", row(A2:D))
will be assigned the value of the row.
And when we gather the last 2 formulas, we have the following:
countif(if(A2:D="inbox", row(A2:A)), row(A2:A))
This means that we will count how many times the value 2 showed up (only existant in row 2), the value 3 showed up (only on row 3), and so on