Jump to content

Running Average of past 12 months for every data point


Go to solution Solved by Chris Harp,

Recommended Posts

I've seen a lot of examples of running average for a year, restarting at Jan 1, but I'm having trouble generating the running average of the past 12 months.  I don't believe now() function should be used at all since its more of an offset() function.  

This doesn't work since it bases it off of the now() date. 

$a.runningAggregate(average(),condition(1y, capsule(now()-1y, now())))  

This doesn't work since it aggregates from Jan-1 thru the date.  

$a.runningAggregate(average(),years())

This doesn't work since it aggregates based on the origin date, being the 1st of the year

$a.runningAggregate(average(),periods(1year,1year,'2016-01-01'))

I'm not sure if this does what I want

$a.runningAggregate(average(),$monthly.beforeStart(1year))     

where monthly is a periodic condition of each month.  Even so, I don't want the 12 month rolling average to calculate from the beginning of each month, rather at the exact date of the date.  And I don't think the formula is even doing the rolling average correctly anyways.  

 

Thanks a lot!

Edited by KantianKinetics
Link to comment
Share on other sites

  • Seeq Team
  • Solution

To create a 1 year period that resets daily at midnight, you can use the following formula:

periods(1y, 1d, '2024-01-01', 'America/Chicago')

When creating your rolling average calculation, use the endKey() in your aggregate function.

$signal.aggregate(average(),$1yearPeriod,endkey())

Let me know if you have any questions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...