Forum Discussion

Stefano66's avatar
Stefano66
Copper Contributor
Mar 02, 2023
Solved

SUMIF and SUMIFS give wrong result

Hi with this data           SUMIF(A1:A4,"IE0032860565",B1:B4) results in 1.13686837721616E-13. The same does SUMIFS(B1:B4,A1:A4,"IE0032860565"). However, SUM(B1:B4) gives zero, which i...
  • JoeUser2004's avatar
    Mar 02, 2023

    Stefano66 

     

    "If a picture is worth a thousand words, an Excel file is worth a thousand pictures". (wink)

     

    Please attach an Excel file, not an image.

     

    We cannot give you a dispositive explanation because the data is probably more precise that you show in the image.  The extra precision might even be invisible in the Excel file because Excel displays (formats) only up to 15 significant digits, rounded.

     

    But I can offer an example that duplicates the symptoms, albeit not the exact values.

     

    Suppose B1 is, in effect, the result of the following calculation:  =2878110+"4.66E-10".

     

    And for simplicity, suppose the string in A1:A4 is "a".

     

    Then =SUMIF(A1:A4,"a",B1:B4) returns 4.66E-10, as we should expect.

     

    But =SUM(B1:B4) returns 0.00E+00, which is exactly zero in Scientific format.

     

    SUM returns exactly zero because of a dubious decision that Excel makes, to wit:  if the two non-zero operands of the last subtraction (or last addition of oppositely-signed values) are "close enough", Excel substitutes the actual infinitesimal difference with exactly zero in an attempt to hide such "close" differences.

     

    But Excel did not implement that rule consistency.  In particular, SUMIF(S) and SUMPRODUCT do not implement the rule.  In fact, it is not implemented consistently within SUM.

     

    -----

     

    The infinitesimal (and possibly hidden) differences in B1:B4 are a common problem that arises from internal binary arithmetic calculations.

     

    In general, the work-around is to explicitly round the SUMIF(S) calculation to the number of decimal places that we expect to be accurate, based on the precision of the original data.

     

     

Resources