# Moving Average

**URL:** <https://forum.inductiveautomation.com/t/moving-average/3141>\
**Category:** Ignition\
**Created:** [July 29, 2011, 11:56am UTC](https://forum.inductiveautomation.com/t/moving-average/3141 "2011-07-29T11:56:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevinmarchand](https://avatars.discourse-cdn.com/v4/letter/k/439d5e/32.png) [@kevinmarchand](https://forum.inductiveautomation.com/u/kevinmarchand)\
**Post date:** [July 29, 2011, 11:56am UTC](https://forum.inductiveautomation.com/t/moving-average/3141/1 "2011-07-29T11:56:06Z")

</div>

Hi,

```
We are curretly using a moving average over 5min at a rate of 1 sec for the machine speed.
I use to log this average speed with rsview 32.
Now with Ignition things could be much easier to log this value but I want to push the envelope. :smiling_imp: 

 :arrow_right: Can I execute a moving average in ignition with script and sqltag and use this tag in my loggin strategy?

  This will give me the opportunity to remove code use for data logging with no real automation purpose.

```

thanks

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [July 29, 2011, 5:15pm UTC](https://forum.inductiveautomation.com/t/moving-average/3141/2 "2011-07-29T17:15:19Z")

</div>

I’m not sure you even need to log a moving average - seems like you can just derive it on the fly when you retrieve the data.

---

<div class="post-metadata">

**Author:** ![kevinmarchand](https://avatars.discourse-cdn.com/v4/letter/k/439d5e/32.png) [@kevinmarchand](https://forum.inductiveautomation.com/u/kevinmarchand)\
**Post date:** [August 17, 2011, 10:23am UTC](https://forum.inductiveautomation.com/t/moving-average/3141/3 "2011-08-17T10:23:16Z")

</div>

Hi Gary,

```
To do this Ill need a DB tag that as a script to do the Movin average.

MVA = SUM(Xn) / n
ex MVA 5 min scan at 1sec n=300
so I need an array of 300 with a roll over last value on a full array get drop.

 :question: Can I do something like this with script :question: 

```

thnaks

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [September 8, 2011, 6:16pm UTC](https://forum.inductiveautomation.com/t/moving-average/3141/4 "2011-09-08T18:16:09Z")

</div>

Yes, you could write a script that gets the average of a value over the last 5 minutes, and then make a DB tag that uses a [runScript expression](http://www.inductiveautomation.com/support/usermanuals/ignition/index.html?gen_advanced_runscript.htm) to drive its value.
