Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

Formula to count rows between positive values

$
0
0

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,

  1. B1="NA" because A1<=0
  2. B2="NA" because A2<=0
  3. B3=3 because A3>0 and ROWS(A1:A3)=3
  4. B4=1 because A4>0 and ROWS(A4)=1
  5. B8=4 because A8>0 and ROWS(A5:A8)=4
AB
1-1NA
2-1NA
313
411
5-1NA
6-1NA
7-1NA
814

What formula can I copy down Column B that will return these values?


Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>