Query total returns much higher value than expect in Access 2010

I have a simple query that correctly returns three records as shown below when no Group By is used.  It simply lists each record separately.

Amt      NbrAffordableUnitsCreated      NbrJobsCreated
$70,000.00      140      
$589.06            10
$1,074,047.00            80

When I add a Group By to sum the Amt, NbrAffordableUnitsCreated, and NbrJobsCreated columns the Amt appears as $1,444,638,537 instead of $1,144,636 while the other two colums sum correctly.  Something is causing the Amt to increase roughly a 1,000 times more than it should.  A copy of the query and output is attached (you may need to enlarge to read it).

Any suggestions on why this is happening would be greatly appreciated.
Liberty4allAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Haris DulicCommented:
No attachment
0
Haris DulicCommented:
Any join involved in this query, since that can be one of the reasons for odd sum?
0
Liberty4allAuthor Commented:
Sorry, I forgot to click Upload File.  There is no join in the query.
SampleQuery.pdf
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Haris DulicCommented:
Can you post the SQL query from the SQL view? it will be more clear , at least to me :)
0
Liberty4allAuthor Commented:
SELECT Sum([main table].[Dollar Amount]) AS Amt, Sum([main table].NbrAffordableUnitsCreated) AS NbrAffordableUnitsCreated, Sum([main table].NbrJobsCreated) AS NbrJobsCreated
FROM [main table]
WHERE ((([main table].[Activity Date])>=#1/1/2014# And ([main table].[Activity Date])<#9/30/2014#) AND (([main table].Approved)=Yes)) OR ((([main table].[Activity Date])>=#1/1/2014# And ([main table].[Activity Date])<#9/30/2014#) AND (([main table].Approved)=Yes))
GROUP BY [main table].Category
HAVING (((Sum([main table].NbrAffordableUnitsCreated)) Is Not Null) AND (([main table].Category)="Investments")) OR (((Sum([main table].NbrJobsCreated)) Is Not Null) AND (([main table].Category)="Investments"));
0
Gustav BrockCIOCommented:
It is most likely rounding errors adding up.
I guess your Dollar Amount field is of data type Double or Single and not Currency.

Try this modification:

SELECT Sum(CCur([main table].[Dollar Amount])) AS Amt

and watch the three records. Then sum these.

/gustav
0
Liberty4allAuthor Commented:
I modified the SQL statement as shown below.  When running it produces "Invalid use of Null".  If I remove the Group By it won't run because the NbrAffordableUnitsCreated field is not part of an aggregate function.  I'm sure the same applies to the field NbrJobsCreated.

Please tell me how to modify it more.  The format of the Dollar Amount field in the table is currency.  

SELECT Sum(CCur([main table].[Dollar Amount])) AS Amt, Sum([main table].NbrAffordableUnitsCreated) AS NbrAffordableUnitsCreated, Sum([main table].NbrJobsCreated) AS NbrJobsCreated
FROM [main table]
WHERE ((([main table].[Activity Date])>=#1/1/2014# And ([main table].[Activity Date])<#9/30/2014#) AND (([main table].Approved)=Yes)) OR ((([main table].[Activity Date])>=#1/1/2014# And ([main table].[Activity Date])<#9/30/2014#) AND (([main table].Approved)=Yes))
GROUP BY [main table].Category
HAVING (((Sum([main table].NbrAffordableUnitsCreated)) Is Not Null) AND (([main table].Category)="Investments")) OR (((Sum([main table].NbrJobsCreated)) Is Not Null) AND (([main table].Category)="Investments"));
0
Gustav BrockCIOCommented:
The format of the field has no importance, only the data type.
If it contains Nulls, modify like this:

SELECT Sum(CCur(Nz([main table].[Dollar Amount],0))) AS Amt

Or how about just filtering out the Nulls:

SELECT
    Sum(CCur([main table].[Dollar Amount])) AS Amt,
    Sum([main table].NbrAffordableUnitsCreated) AS NbrAffordableUnitsCreated,
    Sum([main table].NbrJobsCreated) AS NbrJobsCreated
FROM
    [main table]
WHERE
((([main table].[Activity Date])>=#1/1/2014# And ([main table].[Activity Date])<#9/30/2014#) AND (([main table].Approved)=Yes)) OR ((([main table].[Activity Date])>=#1/1/2014# And ([main table].[Activity Date])<#9/30/2014#) AND (([main table].Approved)=Yes)) And [main table].NbrAffordableUnitsCreated Is Not Null
GROUP BY
    [main table].Category
HAVING
    Sum([main table].NbrJobsCreated) Is Not Null AND [main table].Category="Investments";

/gustav
0
Liberty4allAuthor Commented:
The Dollar Amount field has no null values for records where Category = Investments.

When using the following SELECT statement the dollar amount still shows as $1,444,638,537, or a 1,000 times more than it should.  The other two fields sum correctly.  Can you think of something else I should try, or look at?

SELECT
    Sum(CCur([main table].[Dollar Amount])) AS Amt,
    Sum([main table].NbrAffordableUnitsCreated) AS NbrAffordableUnitsCreated,
    Sum([main table].NbrJobsCreated) AS NbrJobsCreated
FROM
    [main table]
WHERE
((([main table].[Activity Date])>=#1/1/2014# And ([main table].[Activity Date])<#9/30/2014#) AND (([main table].Approved)=Yes)) OR ((([main table].[Activity Date])>=#1/1/2014# And ([main table].[Activity Date])<#9/30/2014#) AND (([main table].Approved)=Yes)) And [main table].NbrAffordableUnitsCreated Is Not Null
GROUP BY
    [main table].Category
HAVING
    Sum([main table].NbrJobsCreated) Is Not Null AND [main table].Category="Investments";
0
Gustav BrockCIOCommented:
How many records holds "main table"?

What are the results if you remove the criteria?

/gustav
0
Liberty4allAuthor Commented:
There are 87,709 records in the main table divided among three categories.  The records go back to 1998.  If I filter only on investments with activity dates from 1/1/2014 to 9/30/2014 I get 3300 records which, in Excel, still sum as the queries above.  If I remove the filters for NbrAffordableUnitsCreated and NbrJobsCreated the dollar amount is the same as above.  This suggests the filters for NbrAffordableUnitsCreated and NbrJobsCreated are being ignored.  Only three records meet the selection criteria as originally written.  

If I add a filter for NbrAffordableUnitsCreated (Is not Null) the result is correct (returns one record).  If I replace the filter for NbrAffordableUnitsCreated with one for NbrJobsCreated (Is not Null) the result is also correct (returns two records).  

The problem may be with the logic used to filter for NbrAffordableUnitsCreated and NbrJobsCreated.  The filters as orginally written visually make sense but are not producing the correct result.  Both of these fields are full of null values except for the three records returned.  Can you suggest another way to write the filters that would fix this?
0
Gustav BrockCIOCommented:
Then I guess you not filter for Sum Is Null but on the individual records.
Move it to the Where clause:

(([main table].NbrAffordableUnitsCreated Is Not Null) AND ([main table].Category="Investments"))
OR
(([main table].NbrJobsCreated Is Not Null) AND ([main table].Category="Investments"));

/gustav
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Liberty4allAuthor Commented:
I will run it without trying to sum results.  Your logic looks fine but for some reason I cannot get it to work.  If the number of such records increases signficantly I can always export the results to Excel and sum results there.

I appreciate your help.
0
Liberty4allAuthor Commented:
Even though I cannot get the logic to work as desired the concept as described by Gustav in his last posting is the solution.  I will run separate queries to get what is needed.  Instead of using

 (([main table].NbrAffordableUnitsCreated Is Not Null) AND ([main table].Category="Investments"))
OR
(([main table].NbrJobsCreated Is Not Null) AND ([main table].Category="Investments"));

I will use something like

(([main table].NbrAffordableUnitsCreated Is Not Null) AND ([main table].Category="Investments"));

in one query and the following in the second.

(([main table].NbrJobsCreated Is Not Null) AND ([main table].Category="Investments"));
0
Gustav BrockCIOCommented:
If both NbrAffordableUnitsCreated and NbrJobsCreated can be Null at the same time, that could explain the difference.

/gustav
0
Liberty4allAuthor Commented:
For the three records that meet the selection criteria that is not the case, but it is for all others.  In theory I could make the filter something like NbrAffordableUnitsCreated Is Not Null AND NbrJobsCreated Is Null on one line, and NbrAffordableUnitsCreated Is Null AND NbrJobsCreated Is Not Null on the second line as this matches the records as they currently exist.  However, this approach returns no records.
0
Gustav BrockCIOCommented:
OK, then I would leave it with the method that works.

/gustav
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.