+ Reply to Thread
Results 1 to 15 of 15

Different Totals For Same Data

  1. #1
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Different Totals For Same Data

    Hi All,

    I observed a very strange problem which has got my head spinning.

    I have a Column of numerical data (45000 Rows).

    When in a cell I sum all the Values of the Column the answer is slight different when the Data is arranged Smallest to Largest Vs Largest to smallest.

    Anyone know why would such a thing happen?

    Attaching the file for reference.
    Attached Files Attached Files
    Cheers!
    Deep Dave

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,933

    Re: Different Totals For Same Data

    Possibly a manifestation of the well-known floating point error in Excel: https://support.microsoft.com/en-us/...sults-in-excel
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Different Totals For Same Data

    Hi @AliGW,

    Thank you for the reply.

    But why would it give different results when Sorted Smallest to Largest Vs Largest To Smallest?

    The numbers are exactly the same. If the whole dataset resulted in incorrect summation when Sorted Smallest to Largest aswell as Largest To Smallest then it was understandable.


  4. #4
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,741

    Re: Different Totals For Same Data

    @ NeedForExcel,

    That is very strange! I get the same behavior when rounding all the values! This is simple addition. I am using Office 2013. Are you getting this with all 2007:2016 versions?
    Dave

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,427

    Re: Different Totals For Same Data

    But why would it give different results when Sorted Smallest to Largest Vs Largest To Smallest?
    I am going to go with AliGW -- possibly floating point error. With floating point errors, the order of summation can make a difference. The classic example of this behavior is something like sum(for n=1 to infinity)(1/n) or sum(for n=infinity to 1)(1/n). Perform this calculation in a hypothetical 4 digit computer, and you can readily see that you will get a different result for adding large to small versus adding small to large.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  6. #6
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,741

    Re: Different Totals For Same Data

    @ MrShorty

    OK. I can follow that. There is a division operation in that model. I don't see how that factors here. These are straight sums. Even with rounding the behavior is the same.

    What am I missing? This is rather disturbing. What could be the remedy?

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,427

    Re: Different Totals For Same Data

    FlameRetired, you don't say how you used the ROUND() function in doing the sums. The thing to remember is that the ROUND() function can only mask, but not eliminate the conversion to binary. When a computer must add 0.01 to anything, it must approximate that terminating decimal number with a non-terminating binary number. At some level, you lose precision whenever you add a small fraction to a larger number (whether that fraction is hand entered or the result of a division operation). The result is a floating point error.

    What remedies are there? The sum(for n=1 to infinity)(1/n) exercise is used to teach and emphasize the importance of always adding from small to large.

    Another remedy, specific to the OP's case, is to completely get rid of fractions and perform the sum as integers, because integers up to 15 digits are represented exactly when converted to double precision binary. As I understand it, this is the basis of the "currency" data types available in VBA and other programming languages. The OP's spreadsheet could have a helper column =ROUND(A2*100,0) that would make each entry an integer, then sum this helper column. If needed at the end, divide by 100.

  8. #8
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Different Totals For Same Data

    Quote Originally Posted by FlameRetired View Post
    @ NeedForExcel,

    That is very strange! I get the same behavior when rounding all the values! This is simple addition. I am using Office 2013. Are you getting this with all 2007:2016 versions?
    Hi @FlameRetired,

    Thank you for taking out time to look into the problem..

    Currently, I have tried it on 2013 & 2016 and it does have the same issue on both versions.. Don't have 2007 & 2010 anymore. Sorry, I haven't updated that in my profile..

  9. #9
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Different Totals For Same Data

    Quote Originally Posted by MrShorty View Post
    The OP's spreadsheet could have a helper column =ROUND(A2*100,0) that would make each entry an integer, then sum this helper column. If needed at the end, divide by 100.
    Hi,

    I will give this a try to see if this works.

    Thank you for the reply..

  10. #10
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,741

    Re: Different Totals For Same Data

    @ MrShorty,

    Thank you for taking the time to explain this ... and suggesting a remedy.

    You are correct. I failed to mention how I rounded. I did not do it the way you suggested, but in the next column rounded all of column A values. You explained why that doesn't work. I never knew that.

  11. #11
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Different Totals For Same Data

    Quote Originally Posted by NeedForExcel View Post
    Currently, I have tried it on 2013 & 2016 and it does have the same issue on both versions.. Don't have 2007 & 2010 anymore. Sorry, I haven't updated that in my profile..
    the same issue is in Ex97 and 2016 64-bit (don't know about Ex5.0)

  12. #12
    Forum Expert cbatrody's Avatar
    Join Date
    04-15-2014
    Location
    Dubai
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    2,136

    Re: Different Totals For Same Data

    I am on Office 2016 and the same issue here as well. I guess it's something to do with what Ali mentioned in post #2 - "Floating-point arithmetic"

    The difference is - 0.1396484375
    Attached Images Attached Images

  13. #13
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,741

    Re: Different Totals For Same Data

    @ NeedForExcel,

    MrShorty's solution works at my end. No problems.

  14. #14
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Different Totals For Same Data

    Thank you all for all the inputs..

    Marking the thread solved as of now..

    Reps added for the valuable inputs..

  15. #15
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,741

    Re: Different Totals For Same Data

    You are welcome. Thank you for the feedback and rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Pivot Table Percentage of grand totals listed under the grant totals
    By Biker102 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 05-31-2017, 01:31 PM
  2. [SOLVED] Cell Refrencing multiple sheet totals to a totals page
    By 007Buff in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-08-2015, 02:23 PM
  3. [SOLVED] How to get cumulative totals from weekly totals (IE sum of all previous cells)?
    By moeburn in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-08-2013, 07:29 PM
  4. [SOLVED] running totals in Pivot Table - removing a user from the totals for the current week
    By eisenbergg in forum Excel Charting & Pivots
    Replies: 12
    Last Post: 09-08-2013, 04:39 PM
  5. [SOLVED] How do I group daily totals into weekly/monthly/quarterly totals
    By situationroom in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-28-2013, 09:58 AM
  6. Method for calculating Invoice Totals and Grand totals
    By sahran4441 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-06-2010, 10:24 PM
  7. Replies: 4
    Last Post: 01-10-2008, 12:31 PM

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