Retun greatest # of cells between nonzero

S

Sean Timmons

OK, I think I've seen this before, but I can't recall how it's done. So, if I
have a table with dates as headers, and a particular row may have, say:


0 0 0 1 0 0 0 0 0 0 2 0 0 1 0 0 0 4 0 0 0 0 0 1

As individual values.


I would like a formula that tells me that the longest time frame between
non-zero fields was 6 days. The actual value of the nonzero cells can vary.
 
G

Gary''s Student

Lets say your data is in row #1. In A2 enter:
=IF(A1=0,1,0)

In B2 enter:
=IF(B1=0,A2+1,0) and copy across.

We see:
0 0 0 1 0 0 0 0 0 0 2 0 0 1 0 0 0 4 0 0 0 0 0 1
1 2 3 0 1 2 3 4 5 6 0 1 2 0 1 2 3 0 1 2 3 4 5 0

Now all we need is:
=MAX(2:2)
 
S

Sean Timmons

That's waht I was looking for! Thank you!

Gary''s Student said:
Lets say your data is in row #1. In A2 enter:
=IF(A1=0,1,0)

In B2 enter:
=IF(B1=0,A2+1,0) and copy across.

We see:
0 0 0 1 0 0 0 0 0 0 2 0 0 1 0 0 0 4 0 0 0 0 0 1
1 2 3 0 1 2 3 4 5 6 0 1 2 0 1 2 3 0 1 2 3 4 5 0

Now all we need is:
=MAX(2:2)
 
T

T. Valko

Try this array formula** :

=MAX(FREQUENCY(IF(A2:X2=0,COLUMN(A2:X2)),IF(A2:X2<>0,COLUMN(A2:X2))))

Note that empty cells will be evaluated as 0.

** array formulas need to be entered using the key combination of
CTRL,SHIFT,ENTER (not just ENTER)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top