I have the following situation in Google Sheets:
I have a set of entries sorted descending with the FALSE option in Cell A1.
I would like to make a running countif in column C, considering the string in Cell B1 and with arrayformula.
The formula should take the sorting option into consideration so, in case I decide to sort the entries in an ascending order, with TRUE in Cell A1, the running countif makes the count from the top down, as it is depicted in the following picture.

Is that possible?
Thanks so much.
>Solution :
Here you have an option with SCAN, instead of counting at each time, it keeps a running count, but hiding when the value doesn’t match B1:
={"Formula";INDEX(IF(B2:B<>B1,"",
SCAN(IF(A1,0,1+COUNTIF(B2:B,B1)),B2:B,LAMBDA(a,v,IF(v<>B1,a,SUM(a,IF(A1,1,-1)))))))}


