3

I have a column of zeros and ones

1
0
0
0
1
1

I want to find out the largest sequence of zeros I have in my column AND how many times it appears.

user40
  • 1,361
  • 5
  • 19
  • 34

2 Answers2

4

With data in column A, in B1 enter:

=IF(A1=1,0,1)

and in B2 enter:

=IF(A2=0,1+B1,0)

and copy down:

enter image description here

the longest sequence is:

=MAX(B:B)

and the number of times it occurs is:

=COUNTIF(B:B,D1)

if the MAX() formula is in D1

Gary's Student
  • 95,722
  • 10
  • 59
  • 99
  • I would add that you can also filter on A for 0s and then on B and choose the maximum value. This will show you the places where the maximum occurs. – Gordon Linoff Jun 04 '15 at 02:14
  • @GordonLinoff Very good idea!..............We could also use *VLOOKUP()* to find that first maximum. – Gary's Student Jun 04 '15 at 02:21
4

If you want to avoid a helper column you can use this "array formula" in C1 for the maximum consecutive zeroes, assuming data in A2:A100

=MAX(FREQUENCY(IF((A2:A100=0)*(A2:A100<>""),ROW(A2:A100)),IF(A2:A100=1,ROW(A2:A100))))

And this formula in C2 for the number of instances

=SUM(IF(FREQUENCY(IF((A2:A100=0)*(A2:A100<>""),ROW(A2:A100)),IF(A2:A100=1,ROW(A2:A100)))=C1,1))

Both formulas need to be confirmed with CTRL+SHIFT+ENTER

I'm assuming you will have continuous data from A2 with only blanks at the end, perhaps

barry houdini
  • 45,615
  • 8
  • 63
  • 81