# How to calculate the average tag value per hour

**URL:** <https://forum.inductiveautomation.com/t/how-to-calculate-the-average-tag-value-per-hour/34855>\
**Category:** Ignition\
**Created:** [May 18, 2020, 7:14pm UTC](https://forum.inductiveautomation.com/t/how-to-calculate-the-average-tag-value-per-hour/34855 "2020-05-18T19:14:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oleh](https://avatars.discourse-cdn.com/v4/letter/o/b4bc9f/32.png) [@Oleh](https://forum.inductiveautomation.com/u/Oleh)\
**Post date:** [May 18, 2020, 7:14pm UTC](https://forum.inductiveautomation.com/t/how-to-calculate-the-average-tag-value-per-hour/34855/1 "2020-05-18T19:14:38Z")

</div>

Hello!  
I need to calculate average value per hour and shield the sum of these values ​​per day, per month.Need to read the active power load graph with only active power. For example:  
hour 1- 20kW  
hour 2-25kW  
hour 3-55 kW…  
and summary of days  
01.05.2020 - 160 kW  
02.05.2020 - 170 kW  
03.05.2020 - 150 kW  
04.05.2020 - 180 kW  
Summary per mouns 2550 kW.

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [May 18, 2020, 7:41pm UTC](https://forum.inductiveautomation.com/t/how-to-calculate-the-average-tag-value-per-hour/34855/2 "2020-05-18T19:41:30Z")

</div>

Hello!

Are you storing this ‘tag value’ in a database?

---

<div class="post-metadata">

**Author:** ![Oleh](https://avatars.discourse-cdn.com/v4/letter/o/b4bc9f/32.png) [@Oleh](https://forum.inductiveautomation.com/u/Oleh)\
**Post date:** [May 19, 2020, 6:38am UTC](https://forum.inductiveautomation.com/t/how-to-calculate-the-average-tag-value-per-hour/34855/3 "2020-05-19T06:38:56Z")

</div>

yes

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 19, 2020, 7:49am UTC](https://forum.inductiveautomation.com/t/how-to-calculate-the-average-tag-value-per-hour/34855/4 "2020-05-19T07:49:44Z")

</div>

This would be relatively easy to do using a tag history query [system.tag.queryHistory](https://docs.inductiveautomation.com/display/DOC80/system.tag.queryTagHistory).  
With the results, you would need to do your calcs.

You could also do a SQL query directly to aggregate the data and return the results, however depending on your history partitioning setup (i.e. if you have partitioning enabled), you may need to union multiple tables together to get the data from previous periods (defaults is monthly partitioning).
