Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BUG in Excel CountIF function

I am having problems with the CountIf Function in Excel.

=COUNTIF(A:A,A2)

The A column consists of these items:

0107791489614255200011140926107503100513

0107791489614255200011140926107503100457

0107791489614255200011140926107503100518

0107791489614255200011140926107503100503

0107791489614255200011140926107503100519

0107791489614255200011140926107503100444

0107791489614255200011140926107503100521

0107791489614255200011140926107503100438

0107791489614255200011140926107503100449

0107791489614255200011140926107503100443

0107791489614255200011140926107503100501

0107791489614255200011140926107503100455

the formula results to 12, even though these set of strings are not really the same at all. It counts these strings as similar strings, I am thinking this is related to its string length?

What do you guys think? I appreciate your help.

like image 811
Synectouche Avatar asked Nov 12 '14 08:11

Synectouche


People also ask

Why is Countif not working in Excel?

COUNTIFS Not Working for Incorrect Range Reference When we use more than one criteria in the COUNTIFS function, the range of cells for different criteria must have the same number of cells. Otherwise, the COUNTIF function won't work.

How do I fix Countif errors?

Solution: Open the linked workbook indicated in the formula, and press F9 to refresh the formula. You can also work around this issue by using SUM and IF functions together in an array formula. See SUMIF, COUNTIF and COUNTBLANK functions return #VALUE!

Why is my Countif function returning 0?

This is the result from the original formula which returned a "0" result. This is the corrected result obtained by changing the formula in the source cell to show a true text result. This is the corrected result obtained by using the asterixes in the COUNTIF formula to 'force' the recognition of the < as text.

Why is my Countif spilling?

Most often, a #SPILL! error occurs when a spill range is blocked by something on the worksheet, and the solution is to clear the spill range of any obstructing data.


2 Answers

+1, A good question. Not really a bug but a feature!

This is due to Excel implicitly converting the inputs to its internal numeric type and losing precision in doing so. Excel's internal numeric type is an IEEE floating point double precision number. (Although it does clever things with formatting and error propagation so it appears to get sums like 1/3 + 1/3 + 1/3 correct).

As they are so similar they all compare as mutually equal.

One remedy would be to prefix each string with ' (single quotation) which will prevent the conversion to the numeric type. Then the COUNTIF value returns 1. (At least in my version of Excel; 2013).

like image 56
Bathsheba Avatar answered Oct 12 '22 22:10

Bathsheba


Preceding the strings with a single apostrophe will not remedy the situation. COUNTIF is designed to interpret data as numerical, where possible, irrespective of the datatype of the values in question. This is sometimes helpful, sometimes (as here) not.

SUMPRODUCT does not exhibit this property:

=SUMPRODUCT(0+($A$1:$A$12=A2))

will return 1, as desired.

Regards

like image 36
XOR LX Avatar answered Oct 13 '22 00:10

XOR LX