Hi,
If you use a GROUP BY (per year, maybe), you have to aggregate the SELECTed
expression. MIN, MAX, FIRST or LAST can do, if there is just one record by
group. If you have a NULL value in any [wkXX] , the result is also NULL.
If a NULL means 0, in that case, you can use Nz( wk16, 0 ) instead of
wk16. That would be much easier if you could get a VERTICAL representation
of your data, AS USUAL for DATABASE, instead of 52 fields, horizontally.
Maybe you already got?
SELECT DatePart("'yyyy", myDate) as TheYear,
DatePart('ww', myDate) as TheWeek,
SUM(myAmount) As TotalPerWeek
FROM myTable
GROUP BY DatePart("'yyyy", myDate), DatePart('ww', myDate)
can produce such a result. If that query is saved under the name Q1, then,
the average, by year, is just
SELECT TheYear, AVG(TotalPerWeek)
FROM q1
GROUP BY TheYear
Isn't it that these two queries look cool in comparison to the lengthy
addition you are obliged to modify?
Hoping it may help,
Vanderghast, Access MVP
KingsWay said:
when I take out the "avg" I get this message:
You tried to execute a query that does not include the specified
expression
<Expr1:
(([wk1]+[wk2]+[wk3]+[wk4]+[wk5]+[wk6]+[wk7]+[wk8]+[wk9]+[wk10]+[wk11]+[wk12]+[wk13]+[wk14]+[wk15]+[wk16]+[wk17]+[wk18]+[wk19]+[wk20]+[wk21]+[wk22]+[wk23]+[wk24]+[wk25]+[wk26]+[wk27]+[wk28]+[wk29]+[wk30]+[wk31]+[wk32]+[wk33]+[wk34]+[wk35]+[wk36]+[wk37]+[wk38]+[wk39]+[wk40]+[wk41]+[wk42]+[wk43]+[wk44]+[wk45]+[wk46]+[wk47]+[wk48]+[wk49]+[wk50]+[wk51]+[wk52])/52)>
as part of an aggregate function. (Error 3122)
Rick B said:
Make that "dividing by 52"
--
Rick B
Rick B said:
If yo uare adding them and then dividing by 2, that is an average. You
don't need the "AVG" in your formula.
--
Rick B
I am trying to average mulitple fields (52 to be exact) and the query
won't
calculate them for me. I am trying to average attendance records for each
year. This is my expression:
Expr1:
Avg(([wk1]+[wk2]+[wk3]+[wk4]+[wk5]+[wk6]+[wk7]+[wk8]+[wk9]+[wk10]+[wk11]+[wk12]+[wk13]+[wk14]+[wk15]+[wk16]+[wk17]+[wk18]+[wk19]+[wk20]+[wk21]+[wk22]+[wk23]+[wk24]+[wk25]+[wk26]+[wk27]+[wk28]+[wk29]+[wk30]+[wk31]+[wk32]+[wk33]+[wk34]+[wk35]+[wk36]+[wk37]+[wk38]+[wk39]+[wk40]+[wk41]+[wk42]+[wk43]+[wk44]+
[wk45]+[wk46]+[wk47]+[wk48]+[wk49]+[wk50]+[wk51]+[wk52])/52)
Thanks for any help you can give me,
Michaela