+ Reply to Thread
Results 1 to 5 of 5

Conditional formula with summation not returning correct result

  1. #1
    Registered User
    Join Date
    09-30-2011
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    19

    Question Conditional formula with summation not returning correct result

    Hey everyone! This isn't necessarily a problem persay, as there are other ways of doing what I'm trying to do, but it just boggles my mind why this has worked just fine for years and now it doesn't in this particular case.

    Here's what's going on, it's very simple:

    ______A___________B__________C__________D_______
    1)_-$16.00_______-$0.50_______"Total 4"____=sum(A1:B1)
    2)__-$4.50________$0.00______"Total 5"_____=sum(A2:B2)
    3) ===========================================
    4)_=sum(A1:A2)__=sum(B1:B2)__"Total"____PROBLEM CODE


    Here's the problem code: =if(sum(A4:B4)=sum(D1:D2),sum(A4:B4),"Error")

    The problem is that even though these two sums are equal I keep getting an error back! I've checked for formatting issues, but these are definitely numbers I'm trying to sum up. But since this anomaly is located in such a simple case, I don't really know what else to check for.

    Interestingly enough, if you start messing with the values in the spreadsheet I attached you'll get varying results. If B7 drops below -$244.65 suddenly the error disappears! Or if you zero out cell C5 the error disappears. None of this makes logical sense to me. Obviously I don't need to set up my spreadsheet like this, I can do it a different way and thereby eliminate the problem, but I wanna know what in the world is going on here!! Any help would be much appreciated!


    frustratingly yours,
    -Mike
    Attached Files Attached Files
    Last edited by Fattyfatfat Kid; 10-03-2011 at 02:06 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Conditional formula with summation not returning correct result

    Click on E10 and then activate the Evaluate Formula icon on the Formula Auditing toolbar. Step through the formula one calc at a time and you'll see the problem occur.

    So, I would change the E10 formula to:

    =SUM(B10:C10) ...and not bother with the checking, the table is simple enough to just trust the basic math.


    Excel does odd things sometimes with precision decimal values. It's not a bad idea to apply forced rounding to your calculations to push out these odd variances before they ever have a chance to take hold your data.

    You could use: =IF(ROUND(SUM(B10:C10),2)=ROUND(SUM(E5:E9),2),SUM(B10:C10),"Error")

    ...but then what's the point, the simpler formula above is just as effective for this simple scenario.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    09-30-2011
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Conditional formula with summation not returning correct result

    Interesting, I never knew about that "Evaluate Formula" button, it's really useful! So now we know WHAT the problem is, but I'm still curious about WHY it's happening, and why it's happening in only this particular case.

    Like I mentioned in my first post, I've been using this format for years in a much bigger spreadsheet and I've never had any problem with it before. And I don't really want to change it because this redundant double checking has saved me hours of work at times!

    Any ideas?
    -Mike

  4. #4
    Registered User
    Join Date
    09-22-2011
    Location
    Washington, USA
    MS-Off Ver
    Excel 2003,2007, 2010
    Posts
    85

    Talking Re: Conditional formula with summation not returning correct result

    Mike

    Here is your answer. Because of the arithmetic of the computer processor, sometimes zero does not equal zero in excel. Look at the attached file - "WHY - Just Because". I added some formulas to show that your answers are not what they appear to be. 14 places past the decimal is your problem in the result. I modified your table with the ROUND formula and it works great. I found this out late one night about 20 years ago trying to balance an excel forecast model for a publically traded company. It had to be right! Don't know how or why I tried to extend the decimals out but found out the rounding issue. You can google it now and find it, but back then google was not around - just brute force attacking the issue. Hope this helps. I use ROUND all the time to prevent this.

    Paul
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    09-30-2011
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Conditional formula with summation not returning correct result

    That's pretty weird, but it explains everything! Thanks for your help JBeaucaire and pmalen!

    In case anyone is reading this in the future and you're interested in learning more about what pmalen was talking about, here's a link that explains it in detail:
    http://support.microsoft.com/kb/78113

    Thanks again!
    -Mike

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1