J
jgroom
I have an access database with a table of info for the past year.
236 records for each day x 365 days.
What I need is an access query that will give me an average for each
day in the quarter, so if I pick quarter 3, I need each day from 7/1
to 9/30, 92 records total.
Each of these records needs an average of the past 30 days.
So an average number from all of the records between 7/1 to 30 days
prior to 7/1.
7/2 would be an average between 7/2 and 6/2.
7/3 would be an average between 7/3 and 6/3.
and so on for each day of the quarter.
I have made a query that will give me the 30 day average for a
specific day.
SELECT QryDate, Avg(Num1) AS AvgNum1, Avg(Num2) AS AvgNum2, avg(Num3)
AS AvgNum3
FROM NumData
WHERE DateStamp Between QryDate And DateAdd("d",-30,QryDate);
So when I run it, it asks for QryDate, if i put in 7/1/2008, it gives
me the average of 30 days prior to 7/1.
This works fine.
I have another query that gives the dates in a quarter.
SELECT Format(DateStamp,"mm/dd/yy") AS Dates
FROM NumData
WHERE Format(DateStamp,"q")=QryQuarter
GROUP BY Format(DateStamp,"mm/dd/yy");
I put in 3 for QryQuarter and it gives me all of the dates for the 3rd
quarter.
I then have a 3rd query that I thought would ask for the quarter and
run the 30 day average for each date in the quarter.
SELECT [30 day average].QryDate, AvgNum1, AvgNum2, AvgNum3
FROM [30 day average]
WHERE Format([30 day average].QryDate,"mm/dd/yyyy") in (Select Dates
from DatesInQuarter);
When I run this 3rd query, it asks for QryDate and QryQuarter both.
If I type in 7/1/2008 and quarter 3, it just shows me the 1 record for
7/1.
If I leave qrydate blank and put in 3 for qryquarter it has no
records.
I need it in a single query because I have a report that runs the
query.
It was temporarly put together with a temp table that held the 30 day
average for each day.
I don't want to run a vbscript that puts these dates in a temporary
table each quarter and the user shouldn't have to do that.
It needs to be all dynamic.
Does anyone know how I can do this without making a temporary table
and without looping within vbscript/vba?
I hope this all makes sense!
Thanks for any help!!
236 records for each day x 365 days.
What I need is an access query that will give me an average for each
day in the quarter, so if I pick quarter 3, I need each day from 7/1
to 9/30, 92 records total.
Each of these records needs an average of the past 30 days.
So an average number from all of the records between 7/1 to 30 days
prior to 7/1.
7/2 would be an average between 7/2 and 6/2.
7/3 would be an average between 7/3 and 6/3.
and so on for each day of the quarter.
I have made a query that will give me the 30 day average for a
specific day.
SELECT QryDate, Avg(Num1) AS AvgNum1, Avg(Num2) AS AvgNum2, avg(Num3)
AS AvgNum3
FROM NumData
WHERE DateStamp Between QryDate And DateAdd("d",-30,QryDate);
So when I run it, it asks for QryDate, if i put in 7/1/2008, it gives
me the average of 30 days prior to 7/1.
This works fine.
I have another query that gives the dates in a quarter.
SELECT Format(DateStamp,"mm/dd/yy") AS Dates
FROM NumData
WHERE Format(DateStamp,"q")=QryQuarter
GROUP BY Format(DateStamp,"mm/dd/yy");
I put in 3 for QryQuarter and it gives me all of the dates for the 3rd
quarter.
I then have a 3rd query that I thought would ask for the quarter and
run the 30 day average for each date in the quarter.
SELECT [30 day average].QryDate, AvgNum1, AvgNum2, AvgNum3
FROM [30 day average]
WHERE Format([30 day average].QryDate,"mm/dd/yyyy") in (Select Dates
from DatesInQuarter);
When I run this 3rd query, it asks for QryDate and QryQuarter both.
If I type in 7/1/2008 and quarter 3, it just shows me the 1 record for
7/1.
If I leave qrydate blank and put in 3 for qryquarter it has no
records.
I need it in a single query because I have a report that runs the
query.
It was temporarly put together with a temp table that held the 30 day
average for each day.
I don't want to run a vbscript that puts these dates in a temporary
table each quarter and the user shouldn't have to do that.
It needs to be all dynamic.
Does anyone know how I can do this without making a temporary table
and without looping within vbscript/vba?
I hope this all makes sense!
Thanks for any help!!