Skip to content
Advertisement

I am getting an incorrect sum in my Access query?

I have a database that tracks parts loans and payback to multiple organizations in my company. I have a query that for a given customer and part name should show a sum of how many have been loaned out (may have been multiple loans), the sum of how many have been paid back (may have been multiple paybacks) and a calculated field that takes the difference of the two. The sum in RcvdQTY is not calculating correctly. In the example in the screenshot below it should be Rcvd = 72, Paid Back = 72, Balance = 0 but it reads 648, 72, 576

Screenshot of my query below: enter image description here

As requested here is my SQL for the query:

Advertisement

Answer

Because your undesired results yielding 648, 72, and 576 are all multiples of 72, you likely are facing duplicate amounts from multiple joins. Consequently, when aggregating it sums all those repeat values.

Looking at your Query Design, consider joining two separate aggregate queries for your final expression, BalancedOwed. Below is my guess at your adjusted SQL. Fix column and table names as needed. All other unnecessary tables were removed:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement