I'm trying to figure out if it's possible to calculate moving average in query. Searching through previous posts, all I could find is:
http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=31806
There are good ideas there. Apparently, this works fine, but what I actually need is different - moving average using certain period. Let me try to explain.
The table is a very simple one, contains one numeric field and one auto number field, sorted by auto number. I need to generate a moving average of the last n periods, for example n=5. Moving average would be an average of "Price" values for the 5 records immediately preceding current record.
Sample:
AutoNum Price MovingAvg
1 100.00 100.00
2 120.00 110.00
3 110.00 110.00
4 105.00 108.75
5 95.00 106.00 (avg of #1-5)
6 70.00 100.00 (avg of #2-6)
7 80.00 92.00 (avg of #3-7)
8 85.00 87.00 (avg of #4-8)
9 87.00 83.40 etc.
10 70.00 78.40
I know, as a last resort I can perform this task using VB code, parsing all the data and generating another table, but with large data sets this could turn to be a headache.
Is there any way to perform this in query?
http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=31806
There are good ideas there. Apparently, this works fine, but what I actually need is different - moving average using certain period. Let me try to explain.
The table is a very simple one, contains one numeric field and one auto number field, sorted by auto number. I need to generate a moving average of the last n periods, for example n=5. Moving average would be an average of "Price" values for the 5 records immediately preceding current record.
Sample:
AutoNum Price MovingAvg
1 100.00 100.00
2 120.00 110.00
3 110.00 110.00
4 105.00 108.75
5 95.00 106.00 (avg of #1-5)
6 70.00 100.00 (avg of #2-6)
7 80.00 92.00 (avg of #3-7)
8 85.00 87.00 (avg of #4-8)
9 87.00 83.40 etc.
10 70.00 78.40
I know, as a last resort I can perform this task using VB code, parsing all the data and generating another table, but with large data sets this could turn to be a headache.
Is there any way to perform this in query?