dengel3587
New Member
- Joined
- Jul 17, 2014
- Messages
- 2
I was having trouble with COUNTIF, so I fell upon this old thread:
http://www.mrexcel.com/forum/excel-questions/84490-countif-not-counting-all-values.html
In the third reply, fairwinds suggests using "=SUMPRODUCT(--(A1:A10={"y","n","n/a"}))" instead of COUNTIF.
For reasons I don't know, using that "--( )" fixed my problem. Specifically, my problem was I was trying to count the number of times "<-50%" appeared in some cells. The list looked something like this: [TABLE="width: 200"]
<TBODY>[TR]
[TD][/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]0%[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]-20 to -25%[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]+20 to +25%[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]0 to +5%[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]<-50%[/TD]
[/TR]
</TBODY>[/TABLE]
Using
=COUNTIF($A$1:$A$5, <criteria> )
worked for things like "0%" and "-20 to -25%", but it didn't work for "<-50%". Then when I used
=SUMPRODUCT(--($A$1:$A$5="<-50%"))
it worked. What does the "--( )" do that makes this^ formula work, but not the COUNTIF or using the SUMPRODUCT without the "--( )" part.
http://www.mrexcel.com/forum/excel-questions/84490-countif-not-counting-all-values.html
In the third reply, fairwinds suggests using "=SUMPRODUCT(--(A1:A10={"y","n","n/a"}))" instead of COUNTIF.
For reasons I don't know, using that "--( )" fixed my problem. Specifically, my problem was I was trying to count the number of times "<-50%" appeared in some cells. The list looked something like this: [TABLE="width: 200"]
<TBODY>[TR]
[TD][/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]0%[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]-20 to -25%[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]+20 to +25%[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]0 to +5%[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]<-50%[/TD]
[/TR]
</TBODY>[/TABLE]
Using
=COUNTIF($A$1:$A$5, <criteria> )
worked for things like "0%" and "-20 to -25%", but it didn't work for "<-50%". Then when I used
=SUMPRODUCT(--($A$1:$A$5="<-50%"))
it worked. What does the "--( )" do that makes this^ formula work, but not the COUNTIF or using the SUMPRODUCT without the "--( )" part.