cancel
Showing results for
Did you mean:

# Alteryx designer Discussions

###### #SANTALYTICS

Gather all 9 clues to complete the final Weekly Challenge on Dec 16!

SOLVED

## Moving average calculation over a date range

Meteor

Trying to perform a moving average over a range of dates for a specific value.  In the example data set attached, the range between Finish and Start Date-Time is 15 days.    Step one involves a moving average using one of the value columns (i.e. Value1) using values in rows between the Finish and the Start dates.  You will see there is not a consistent number of records to average over by date.  This step I can't quite figure out.   The output must calculate back from the Finish Date over the last 15 days.  I.e. For row 1, the average is equal to just the value for that day.  Once there are over 15 days, use data only within the 15 day window.

StartDate is not required as the 15 could be in a formula. Any hints?

Step two requires I then perform across all rows (Value2, Value3) but that can wait till I figure out step 1.

Thanks

Alteryx Certified Partner

There are a few ways to achieve the desired result here, I choose to use a Batch Macro. What this macro does is for each day (control parameter), it matches all the relevant date records (last 15 days), and averages all the values during that time period.

Check out the attached solution and let me know if this works for you.

Nebula

I tend to do this a slightly different way to @CharlieS.

First make a list of all the dates (value dates, start and end dates).

Next create running totals including a count column

Then join to start and end dates to make averages.

Highlighted
Meteor

Charlie,

Your batch macro was spot on and solve the challenging problem of how to accurately calculate averages.  I worked through each calculation to assure indeed it was correct.

Thanks

Steve

Meteor

Your solution had the same problem I struggled to accurately calculate averages over a group.  It is not simply taking averages of averages.  If one changes the 'Count = 1' to a summarized count of the number of entries for the day, your solution is closer but still not accurate.  Here is a link to a more rigorous explanation of why an average of averages is not correct.  I did learn one technique from your solution - so thanks.

Steve

https://math.stackexchange.com/questions/95909/why-is-an-average-of-an-average-usually-incorrect

Labels