Calculate Moving (Rolling) Averages (1 Viewer)

cft

Registered User.
Local time
Today, 03:52
Joined
Dec 31, 2001
Messages
52
I need information regarding how to calculate a moving average over the most recent 6 months-to-date. I searched the postings for "Moving" and "Rolling" averages, but came up empty. Any Ideas?
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 22:52
Joined
Feb 19, 2002
Messages
43,374
The averages are calculated normally. The only thing you need to do is use selection criteria to select the data from the correct timeframe. Create your query and then add the following Where clause:

Where YourDate Between [Enter Start Date] and [Enter End Date];

The user will be prompted for the two dates. You could also use the Date() and DateAdd() functions if you wanted to calculate the date range on the fly.
 

cft

Registered User.
Local time
Today, 03:52
Joined
Dec 31, 2001
Messages
52
Thank you! This is good information. I am trying to figure out how to use this to automate the between function to read Now() or "Today's Date" and calculate the Average for the past 180 days, or 90 days, etc... Is there any SQL or Expression building for this? I know just enough to know what I want, but not enough to get there. Thanks.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 22:52
Joined
Feb 19, 2002
Messages
43,374
Use Date() rather than Now() since you don't need the time of day. Normally you would use DateAdd() to add or subtract (use a negative number rather than a positive) some time interval. Since the interval you want is days, you can use the following shortcut -

Date() - 180

Days is assumed. If you need to use a different interval, you'll need to use DateAdd() where you can specify whether you are adding days, months, years, etc.
 

cft

Registered User.
Local time
Today, 03:52
Joined
Dec 31, 2001
Messages
52
This works great! Thanks for your input and help!
 

Cosmos75

Registered User.
Local time
Yesterday, 21:52
Joined
Apr 22, 2002
Messages
1,281
Must Try!

This goes on my must-try list!! Am trying to create a graph that show X weeks cost and show the moving average from week to week BUT it will go like so..

Average of Week 1 through Week 2
Average of Week 1 through Week 3
Average of Week 1 through Week 4
...
Average of Week 1 through Week X

Kinda wierd.

Edit : Feel free to post a solution to my problem if you know it! If I figure it out I'll try to remember to post any solution I've found.
 
Last edited:

Users who are viewing this thread

Top Bottom