Reverse CountIf?

AWHITTY

New Member
Joined
May 1, 2018
Messages
2
Hi all,

Hopefully a quick query.

I have two columns of data Column A is date and time

14/03/2017 00:00 0 0
14/03/2017 00:02 6 1
14/03/2017 00:04 0 0
14/03/2017 00:06 0 1
14/03/2017 00:08 0 2
14/03/2017 00:10 6 3

Column B has a numerical figure.

What I want to do in column C is count how many proceeding timesteps (rows) have a column B value of 0.

So kind of a countif but needs to count looking back up the rows instead of down?

Thanks!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi. As long as you use headers this works in C2:

=IF(B1=0,C1+1,0)
 
Upvote 0
Your data implies column B will contain zeroes and then ONE (and only one) occurrence of a non-zero.
However this should work, irrespective of how many occurrences of non-zero occur together in column B

in C1 put 0

in C2
=IF(B1<>0,0,C1+1)
and copy down the column

I suspect this can be done with COUNTIF/COUNTIFS but I couldnt come up with solution via that method
 
Upvote 0
try this:

<b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: rgb(255,255,255);border-collapse: collapse; border-color: rgb(187,187,187)"><thead><tr style=" background-color: rgb(218,231,245);color: rgb(22,17,32)"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">C2</th><td style="text-align:left">=IF(<font color="Blue">B1<>0,0,COUNTIFS(<font color="Red">B$1:B1,0</font>)-IFERROR(<font color="Red">COUNTIF(<font color="Green">B$2:INDEX(<font color="Purple">B:B,LOOKUP(<font color="Teal">99999999,1/B$1:B1,ROW(<font color="#FF00FF">B$1:B1</font>)</font>)</font>),0</font>),0</font>)</font>)</td></tr></tbody></table></td></tr></table><br />



Excel 2013/2016
ABC
1dateNumtest
214/03/2017 00:0000
314/03/2017 00:0261
414/03/2017 00:0400
514/03/2017 00:0601
614/03/2017 00:0802
714/03/2017 00:1063
814/03/2017 00:1170
914/03/2017 00:1200
1014/03/2017 00:1301
1114/03/2017 00:1402
1214/03/2017 00:1503
1314/03/2017 00:1634
1414/03/2017 00:1700
1514/03/2017 00:1801
1614/03/2017 00:1902
1714/03/2017 00:2003
1814/03/2017 00:2134
1914/03/2017 00:2240
2014/03/2017 00:2300
2114/03/2017 00:2401
2214/03/2017 00:2552
Sheet1
 
Upvote 0
or perhaps....in C2 copied down
=IF(B1=0,C1+1,0)*ISNUMBER(B1)
 
Upvote 0
Headers makes this simpler. I used an array formula:


Book1
ABC
1DateNumResult
214/03/2017 00:0000
314/03/2017 00:0261
414/03/2017 00:0400
514/03/2017 00:0601
614/03/2017 00:0802
714/03/2017 00:1063
Sheet1
Cell Formulas
RangeFormula
C2{=ROW()-LOOKUP(2,1/($B$1:$B1<>0),ROW($B$1:$B1))-1}
Press CTRL+SHIFT+ENTER to enter array formulas.


WBD
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top