I need a formula in Google Sheets to count the number of rows between each positive number in a column.
In Column B of the table below, for every value in Column A that is less than, or equal to zero, <=0, I want the text NA. For any row where Column A is greater than zero, >0, I want the total number of rows between the previous row that also contained a number >0 (or the first row if there is none prior) up to and including the current row.
For example,
B1="NA"becauseA1<=0B2="NA"becauseA2<=0B3=3becauseA3>0andROWS(A1:A3)=3B4=1becauseA4>0andROWS(A4)=1B8=4becauseA8>0andROWS(A5:A8)=4
| A | B | |
|---|---|---|
| 1 | -1 | NA |
| 2 | -1 | NA |
| 3 | 1 | 3 |
| 4 | 1 | 1 |
| 5 | -1 | NA |
| 6 | -1 | NA |
| 7 | -1 | NA |
| 8 | 1 | 4 |
What formula can I copy down Column B that will return these values?