Divide by the minimum non-zero number in a range of cells

O

Opus

I need to find the minimum non-zero number in a range of cells that contains
some zeroes. So that I can divide by the minimum number. Any ideas?

If I just use the MIN function, it returns a value of 0, then when my
formula divides by that I get the divide by zero error.
 
J

Jarek Kujawa

=MIN(IF(A1:A10;A1:A10))

this is an array-formula so CTRL+SHIFT+ENTER instead of simply
entering it
 
J

Jacob Skaria

Suppose you have the numbers in Column A use the below formula to return the
minimum non zero number. Hope you dont have negative numbers..

=SMALL(A:A,COUNTIF(A:A,0)+1)

If this post helps click Yes
 
A

Allllen

Hello Opus,

This works, assuming your data is in cells A1 to G1.

=MIN(IF($A$1:$G$1=0,MAX($A$1:$G$1),$A$1:$G$1))

You have to submit it as an array formula (type the formula then press
Ctrl+Shift+Enter).

What it does is look at all the values individually, and any time it finds a
zero it thinks about it as the biggest number in the range instead (thereby
excluding it from the MIN).
 
A

Allllen

This works, assuming your data is in cells A1 to G1.

=MIN(IF($A$1:$G$1=0,MAX($A$1:$G$1),$A$1:$G$1))

You have to submit it as an array formula (type the formula then press
Ctrl+Shift+Enter).

What it does is look at all the values individually, and any time it finds a
zero it thinks about it as the biggest number in the range instead (thereby
excluding it from the MIN).
 
G

Gary''s Student

=MIN(IF(A1:A10<>0,A1:A10))

NOTE:

This is an array formula that must be entered with CNTRL-SHFT-ENTER instead
of just the ENTER key.
 
A

Allllen

=MIN(IF(a1:g1=0,max(a1:g1),a1:g1)
array formula: press ctrl+shift and enter to submit it
 
S

Shane Devenshire

Hi,

If you don't want an array formula try this

=SUMPRODUCT((A1:A7<>0)*(MIN(A1:A7)=A1:A7)*A1:A7)
 
B

barry houdini

Shane said:
If you don't want an array formula try this

=SUMPRODUCT((A1:A7<>0)*(MIN(A1:A7)=A1:A7)*A1:A7)

Surely that won't always return the correct result? If all cells A1:A7
contain the number 1 then that formula will give you 7
 
J

JoeU2004

Shane Devenshire said:
If you don't want an array formula try this
=SUMPRODUCT((A1:A7<>0)*(MIN(A1:A7)=A1:A7)*A1:A7)

Doesn't work for me. Test with A1:A7 = {0,3,3,2,3,3,0}. Returns zero. It
is easy to see why: MIN(A1:A7) is a constant, namely the smallest in the
range. Since that would be zero, the very case that the OP wants to
exclude, the SUMPRODUCT should always be zero.


----- original message -----
 
J

Jarek Kujawa

corrected:

=MIN(IF(A1:A10,A1:A10))



=MIN(IF(A1:A10;A1:A10))

this is an array-formula so CTRL+SHIFT+ENTER instead of simply
entering it




- Poka¿ cytowany tekst -
 
T

T. Valko

If you don't want an array formula

Assuming there will always be at least 1 non-zero cell and there's no text
in the range:

=MIN(INDEX(((A1:A7<>0)*A1:A7)+((A1:A7=0)*1E+100),,1))
 
S

Shane Devenshire

Well that's pretty interesting, unfortunately I cleared my test range and
can't duplicate the original results.

Alternative:

=SUMPRODUCT(MIN(9^9*(A1:A8=0)+A1:A8))

hopefully this is a little better.
 
O

Opus

Thank you all for your replies. This is what occured to me late last night
and what I wound up doing:

I realized that what I was looking for here was the Maximum number resulting
from dividing a constant by the Minimum number in a range. So I did

=IF(A1=0,"",Constant/A1)

and copied it for each cell in my original range creating a range of results
in a separate column B that I later hid. This weeded out all the cells
containing zero.

I then used

=Max(B1:B10)

to obtain the result I was actually after.
 
J

JoeU2004

T. Valko said:
=MIN(INDEX(((A1:A7<>0)*A1:A7)+((A1:A7=0)*1E+100),,1))

I think this is the most reliable expressions of this ilk; "reliable"
because I believe it works for all values in A1:A7 less then 1E100, even if
MIN(A1:A7) is 2^53 or more less than 1E100.

However, I believe that expression fails if MIN(A1:A7) is greater than
1E100. Moreover, it can be simplified. I believe the following is more
reliable:

=min(index(A1:A7+2*max(A1:A7)*(A1:A7=0),,1))

I believe that works as long as MAX(A1:A7) is less than 2^1023.

We could extend the allowed numerical range for A1:A7 somewhat by replacing
"2*" with a smaller factor larger than 1; the smallest constant factor is
1.00000000000001. But it does not seem to be worth the trouble.

PS: Personally, I don't feel that any of this is worth the trouble just to
avoid the straight-forward array formula, as much as I dislike array
formulas in general.


----- original message -----
 
J

JoeU2004

Shane Devenshire said:
=SUMPRODUCT(MIN(9^9*(A1:A8=0)+A1:A8))

Why 9^9? Why not something more straight-forward like 10^10? That can
written as the constant 1E10?

And why is this any better than Biff's (T.Valko's) formulation that uses
MIN(INDEX(...))? I presume you saw his, since you posted your follow-up
more than 4 hours later to the same news server, I believe.

In any case, as I noted regarding Biff's formula, expressions of this ilk
limit MAX(A1:A8) to whatever factor you use, be it 9^9, 1E10 or 1E100. So
it would behoove you to use a larger factor like 1E10 or even 1E100.

And to that end, I think it would be better to replace any constant factor
(e.g. 9^9) with 2*max(A1:A8). That limits MAX(A1:A8) to 2^1023, about half
the biggest value allowed.

I also noted that we can extend the range of values for MAX(A1:A8) by
replacing the factor 2 with a smaller factor larger than 1; the smallest
constant factor is 1.00000000000001.

But none of this seems to be worth the trouble just to avoid the
straight-forward array formula solution, as much as I don't like array
formulas myself.


----- original message -----
 
J

JoeU2004

Teethless mama said:
=MIN(INDEX(10^10-(A1:A7<>0)*(10^10-A1:A7),))

As I noted in my comments about Biff's (T.Valko's) formula, expressions of
this ilk limit MAX(A1:A7) to whatever factor you use, 10^10 in your case.
(Why not simply write 1E10?)

But your expression suffers from the additional limitation that MIN(A1:A7)
cannot be more than about 2^52 less than 1E10 or whatever factor you choose.

Arguably, since the OP is worried about a minimum of zero (sometimes?), you
might think that MIN(A1:A7) cannot be 2^52 less than 1E10. (But is the
operative word "sometimes"?) But considering my first comment, ironically
it behooves you to choose a larger factor, unless the OP gives us an upper
bound.

Much ado about nothing. Personally, I don't feel that any of this is worth
the trouble just to avoid the straight-forward array formula, as much as I
dislike array formulas in general.


---- original message -----
 
T

T. Valko

PS: Personally, I don't feel that any of this is worth the
trouble just to avoid the straight-forward array formula

I agree completely. It was just an academic exercise.
 
J

JoeU2004

T. Valko said:
I agree completely. It was just an academic exercise.

Likewise. Always fun ;-). Also gives us a chance to learn new approaches.


----- original message -----
 

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