# How to calculate moving-window values

**URL:** <https://forum.inductiveautomation.com/t/how-to-calculate-moving-window-values/33244>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [March 19, 2020, 3:41pm UTC](https://forum.inductiveautomation.com/t/how-to-calculate-moving-window-values/33244 "2020-03-19T15:41:33Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 19, 2020, 4:58pm UTC](https://forum.inductiveautomation.com/t/how-to-calculate-moving-window-values/33244/2 "2020-03-19T16:58:38Z")

</div>

Consider scripting a FIFO of timestamps and values. Hold the FIFO in a list in your python script module for efficiency. On script reloads, preload your FIFO from the DB. Otherwise, when the tag changes or on some timer event, append to the FIFO list (timestamp and new value), and compute against the oldest entry. Remove the oldest from the list if it falls before your sliding window.

If you don't want to script it, this post has a similar operation done with expression tags and functions from my free add-on module:

> [@Tag Value Delta Calculation](http://forum.inductiveautomation.com/t/tag-value-delta-calculation/32221):
>
> Hello all, I am attempting to create a tag that will represent the change in an OPC tags value over the previous 60 seconds. I have flirted with a few ideas on how to do this, but have run into some potential issues with each version i tried. First, I attempted to just create an expression tag that is on a much slower scan class that takes the value of the OPC tag every 60 seconds (scan class execution). That way, there would be a tag that represents the current count value (OPC tag) as well a…

---

_[View the full topic](https://forum.inductiveautomation.com/t/how-to-calculate-moving-window-values/33244)._
