Full Version: Incorrect SUM Value
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
timbreeding
Alright. I'm running a query with some columns that return a value base on whether a field is null.

CODE
ATTAINED: IIf((IsNull([Actuals.PROJ_ACT_ID]) Or ([Actuals.ACT_PERC_COM]<=[Baseline.ACT_PERC_COM])),0,1)


So this either has a 0 or a 1 based on the condition. So in another query I did a simple SUM grouping on this column and it returns 22264. But if I pull the column into a spreadsheet, the number adds up to 92. What gives?
GroverParkGeorge
You have indicated that there is a discrepency (and a huge one at that), but re-reading through the description of the problem, I am still not sure which value you believe to be correct.


How many records are returned altogether? How many records inthat recordset have a value of 1 in the Attained column? Is it 92? or is it 22264?
timbreeding
There are 195 total records and 92 of them return a value of 1. Thus, the sum should be 92.
GroverParkGeorge
And since we haven't seen the full SQL of either query, I'm going to have to guess that it is something like this:

Select Sum([Attained]) as TotalAttained FROM Query1

This assumes that the field [Attained] is in Query1 and that it contains the expression described in your first post?

Is that accurate?
vtd
Try:
CODE
ATTAINED: ((IsNull([Actuals.PROJ_ACT_ID])) Or ([Actuals.ACT_PERC_COM]<=[Baseline.ACT_PERC_COM])) + 1
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.