?
Solved

Incorrect Sum in Access Query

Posted on 2006-07-04
4
Medium Priority
?
325 Views
Last Modified: 2011-09-20

I have a simple query which I would like to sum the amount. The Select query (in SQL view) without the sum is:

SELECT Line_Items.IO, Line_Items.Amount, Line_Items.Date
FROM Line_Items
WHERE (((Line_Items.Date)=#4/3/2006#));

It gives these results:

Code      Amount      Date
1237540      -1126.02      2006-04-03
1237540      -2375      2006-04-03
1237540      -1885.5      2006-04-03
1237540      1126.02      2006-04-03
1237540      2375      2006-04-03
1237540      1885.5      2006-04-03
1728684      -1126.02      2006-04-03
1728684      -2375      2006-04-03
1728684      -1885.5      2006-04-03
1728684      2375      2006-04-03
1728684      1126.02      2006-04-03
1728684      1885.5      2006-04-03

I want to sum the amount, grouped by the Code.

The sql is:

SELECT Line_Items.IO, Sum(Line_Items.Amount) AS SumOfAmount, Line_Items.Date
FROM Line_Items
GROUP BY Line_Items.IO, Line_Items.Date
HAVING (((Line_Items.Date)=#4/3/2006#));

The results are:

IO      SumOfAmount      Date
1237540      0                                      2006-04-03
1728684      -4.54747350886464E-13      2006-04-03

As you can see, the sum for Code 1237540 is correct, while the sum for Code 1728684 is not correct, even though they contain identical amounts.

Why?
0
Comment
Question by:valkyri
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 17037443
Would u be happy if the value was rounded?

SELECT Line_Items.IO, Round(Sum(Line_Items.Amount),2) AS SumOfAmount, Line_Items.Date
FROM Line_Items
GROUP BY Line_Items.IO, Line_Items.Date
HAVING (((Line_Items.Date)=#4/3/2006#));
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17037449
Access is expanding your double value, it does this, and because its greater than 15, it puts in the -13
This problem occurs with VBA coding as well, not sure how and why Access calculates to so many decimal places, probably due to length of datatype double
0
 

Author Comment

by:valkyri
ID: 17037474

I must be losing my mind, I've had this problem before. Oh well, thank you for reminding me.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17037511
No probs
This issue annoys me also
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question