# Time Weighted Average

**URL:** <https://forum.inductiveautomation.com/t/time-weighted-average/18926>\
**Category:** General Discussion\
**Created:** [July 22, 2018, 1:11pm UTC](https://forum.inductiveautomation.com/t/time-weighted-average/18926 "2018-07-22T13:11:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abishur](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/abishur/32/9096_2.png) [@abishur](https://forum.inductiveautomation.com/u/abishur)\
**Post date:** [July 22, 2018, 1:11pm UTC](https://forum.inductiveautomation.com/t/time-weighted-average/18926/1 "2018-07-22T13:11:41Z")

</div>

This might be a better question for Stack Overflow, however I was curious if anyone here has ever delt with this issue.

I have a client who wants to use a third party web-dashboard for viewing historical data. They are concerned about making sure they are getting good averaged values, however the data is stored from Ignition as it changes without any sort of consistent time gap. Is there a direction I can point them in to have their SQL queries take the duration a tag was at a certain value into consideration, or is their only recourse the AVG command and accepting any skewing that may occur?

---

<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:** [July 22, 2018, 1:46pm UTC](https://forum.inductiveautomation.com/t/time-weighted-average/18926/2 "2018-07-22T13:46:04Z")

</div>

They can use the SQL lag() window function to give you the timestamp preceding a sample, from which you can compute a weight for that sample. If you want to minimize difficulties with external tools, use transaction groups to record into wide tables on fixed intervals.

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [July 23, 2018, 2:19pm UTC](https://forum.inductiveautomation.com/t/time-weighted-average/18926/3 "2018-07-23T14:19:30Z")

</div>

Have you considered having the third party application ask Ignition for the data via the WebDev module and [system.tag.queryTagHistory](https://docs.inductiveautomation.com/display/DOC79/system.tag.queryTagHistory) ?

---

<div class="post-metadata">

**Author:** ![abishur](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/abishur/32/9096_2.png) [@abishur](https://forum.inductiveautomation.com/u/abishur)\
**Post date:** [July 23, 2018, 9:08pm UTC](https://forum.inductiveautomation.com/t/time-weighted-average/18926/4 "2018-07-23T21:08:16Z")

</div>

I had not heard of the lag function in SQL. That looks extremely promising for their application.

I had not considered system.tag.queryTagHistory, it wouldn’t work for their situation, but I will be bookmarking that for my own information, thanks!
