Sum if

H

Harvey Waxman

I have a column of percentages with lots of places beyond the decimal point. I
want to count the number of occurrences of a single percentage, say 5%.

If I could round up all the values to only 2 decimal places (.05 for example)
it would be easy enough.

Instead i tried this but got a value of 0 which isn't quite true.

{=SUM(IF(A1:A98,">5%",IF(A1:A98,"<6%")))}

Can someone help?
 
J

JE McGimpsey

Harvey Waxman said:
I have a column of percentages with lots of places beyond the decimal point.
I
want to count the number of occurrences of a single percentage, say 5%.

If I could round up all the values to only 2 decimal places (.05 for example)
it would be easy enough.

Instead i tried this but got a value of 0 which isn't quite true.

{=SUM(IF(A1:A98,">5%",IF(A1:A98,"<6%")))}

Can someone help?

One way:

=SUMPRODUCT(--(ROUNDUP(A1:A98,2)=0.06)))

another:

=COUNTIF(A1:A98,">0.05") - COUNTIF(A1:A98,">0.06")
 
H

Harvey Waxman

JE McGimpsey said:
One way:

=SUMPRODUCT(--(ROUNDUP(A1:A98,2)=0.06)))

another:

=COUNTIF(A1:A98,">0.05") - COUNTIF(A1:A98,">0.06")

By the way, is there a rule to know how to express the criteria? For example,
COUNTIF needs ,">0.06" but IF needs >.06.
 
J

JE McGimpsey

One way:

=SUMPRODUCT(--(ROUNDUP(A1:A98,2)=0.06)))

another:

=COUNTIF(A1:A98,">0.05") - COUNTIF(A1:A98,">0.06")

By the way, is there a rule to know how to express the criteria? For
example,
COUNTIF needs ,">0.06" but IF needs >.06.[/QUOTE]

Not really - you could use ">0.06", ">.06", ">6%", etc. for either
function.

XL will translate each of them to the binary machine representation
(IEEE-754 floating point double):

00111111101011110101110000101000111101011100001010001111010111000
 
H

Harvey Waxman

COUNTIF needs ,">0.06" but IF needs >.06.

Not really - you could use ">0.06", ">.06", ">6%", etc. for either
function.[/QUOTE]

I get an error if I use quotes with the criterion in an IF statement. (see
original question)

I'm trying to discern when it is necessary to surround the criteria with quotes
and when it isn't - i.e. which functions need what syntax.
 
J

JE McGimpsey

Harvey Waxman said:
I get an error if I use quotes with the criterion in an IF statement. (see
original question)

I'm trying to discern when it is necessary to surround the criteria with
quotes
and when it isn't - i.e. which functions need what syntax.


Take a look at XL Help. COUNTIF and SUMIF are functions which can take
constants, cell references or expressions. Expressions need to be text
strings, so they can be of the form

">0.06"
"<.2"
">=" & SUM(A1:A10)

etc.

OTOH, with IF, the comparison argument has to evaluate to a boolean TRUE
or FALSE (for which XL interprets a numeric, non-zero value as TRUE and
a numeric value of zero as FALSE).

Since ">0.06" doesn't evaluate to either a boolean or numeric value,

=IF(">0.06","Yes","No")

will return #VALUE!

Internally, in XL's evaluation of the formula

=IF(A1>0.06,"Yes","No")

the criterion A1>0.06 is evaluated *before* it's sent to the IF
function. Only its result (TRUE/FALSE) is passed to IF.
 
H

Harvey Waxman

JE McGimpsey said:
the criterion A1>0.06 is evaluated *before* it's sent to the IF
function. Only its result (TRUE/FALSE) is passed to IF.


Thank you
 
S

ShaneDevenshire

Hi Harvey,

First thing your formula is not complete: IF(Test,True,False). It appears
you are trying to work with items between 5% and 6%, in effect you want a
formula like:

=SUM(IF((A1:A9>=5%)*(A1:A9<6%),1))

I have left out the false part because you can (or you can write it:

=SUM(IF((A1:A9>=5%)*(A1:A9<6%),1,0))

Both of these formulas are entered as arrays.

You can also enter the non-array formula:

=SUMPRODUCT((A1:A9>=5%)*(A1:A9<6%))
or
=SUMPRODUCT(--(A1:A9>=5%),--(A1:A9<6%))
 
H

Harvey Waxman

Super, many thanks

ShaneDevenshire said:
First thing your formula is not complete: IF(Test,True,False). It appears
you are trying to work with items between 5% and 6%, in effect you want a
formula like:

=SUM(IF((A1:A9>=5%)*(A1:A9<6%),1))

I have left out the false part because you can (or you can write it:

=SUM(IF((A1:A9>=5%)*(A1:A9<6%),1,0))

Both of these formulas are entered as arrays.

You can also enter the non-array formula:

=SUMPRODUCT((A1:A9>=5%)*(A1:A9<6%))
or
=SUMPRODUCT(--(A1:A9>=5%),--(A1:A9<6%))
 

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

Similar Threads

Rounding question 9
=Trend question 2
office 2003 Excel - SUM 3
Stop Rounding Currency 20
Sum Function 3
Rounding problem 9
HELP: Excel 2010; finding duplicate numbers 5
Data Validation error (XL2003 and XL2007) 1

Top