Is it something to do with if last month is null, go to the previous month,
if that month is null, go to the previous month?
Do you mean that you have records for the EmployeeID, where
[LoggedMonthYear] is NULL? Or do you mean that you have values in that field
like 1/10/08, 2/15/08, 4/3/08, 5/23/08?
If my tests are correct, the following should work.
SELECT yourTableName.EmployeeID,
Avg(yourTableName.[AccuracyScore]) AS RollingAvg,
Count(yourTableName.[AccuracyScore]) AS RecCount
FROM yourTableName
INNER JOIN (SELECT T.EmployeeID, T.LoggedMonthYear,
DCount("EmployeeID","yourTableName","EmployeeID = " & [T].[EmployeeID] & "
AND [LoggedMonthYear] >= #" & [T].[LoggedMonthYear] & "#") AS Rank
FROM yourTableName AS T
WHERE (((DCount("EmployeeID","yourTableName","EmployeeID = " &
[T].[EmployeeID] & " AND [LoggedMonthYear] >= #" & [T].[LoggedMonthYear] &
"#"))<4))
ORDER BY T.LoggedMonthYear DESC) AS Last3 ON (yourTableName.LoggedMonthYear
= Last3.LoggedMonthYear) AND (yourTableName.EmployeeID = Last3.EmployeeID)
GROUP BY yourTableName.EmployeeID;
This uses the DCOUNT function to identify a ranking (based on the # of
records with a LoggedMonthYear value >= the current record) for each entry
for each employee. This gives you the ability to filter on Rank < 4. It
then joins the table to this subquery, and computes the average accuracy and
provides you with a count of the number of records that were included in the
average (for those that have less then 3 entries).
--
HTH
Dale
email address is invalid
Please reply to newsgroup only.
buzzmcduffie said:
employeeID - text
LoggedMonthYear - date
AccuracyScore - percentage
One record per employee per month. Not all employees have a record for
every month. I need the average per employee for the last 3 months of DATA
not actual months.
Emp 1 had a score for Jan Feb Mar Apr May = I want to see Mar, Apr, May
Emp 2 had a score for Jan Feb (does not have a score for March) Apr May - I
want to see Feb, Apr, May
I want Employee 1 average score for the last 3 months of data (MAR, APR, MAY)
I want Employee 2's average score for the last 3 months of data. (FEB, APR,
MAY)
Is it something to do with if last month is null, go to the previous month,
if that month is null, go to the previous month?
Or do I give each record a number - month 1 of data, month 2 of data etc.
thanks for whatever you can do..I'm stuck
Dale Fye said:
I'd be willing to give it a shot, but need a lot more information than what
you have provided here. What is your table structure? Is there one, or more
than one record per month for each employee? Can you provide some sample
data, and what you want the query output to look like for that sample data?
--
Dale
email address is invalid
Please reply to newsgroup only.
buzzmcduffie said:
I still need help with the subquery if anyone is up to the challenge of
teaching a novice to get a rolling average.
thanks!
:
I would like the last 3 months that had data for each employee..
Emp 1 had data in Jan Feb Mar Apr May = I want to see Mar, Apr, May
Emp 2 had data in Jan Feb Apr May - I want to see Feb, Apr, May
Everyone is going to be alittle different.
SELECT qryQA_RollingMonths1.Task, qryQA_RollingMonths1.EmployeeID,
qryQA_RollingMonths1.LoggedMonthYear, qryQA_RollingMonths1.AccuracyScore,
DateSerial(Year([LoggedMonthYear]),Month([LoggedMonthYear]),1) AS FirstOfMonth
FROM qryQA_RollingMonths1;
now what?
thanks!
.
That's going to be pretty complicated. You'll need to create a subsidiary
query with one record per month, per employee; use a calculated field
FirstOfMonth: DateSerial(Year([datefield]), Month([datefield]), 1)
Create a totals query grouping by the employeeID and this field to get one
record per month. Include any totals for the month that you want to include in
the report.
Then, use this query in a Subquery using the TOP VALUES property of the
subquery.
John W. Vinson [MVP]