# Historian Tag Data - Calculating Runtime

**URL:** <https://forum.inductiveautomation.com/t/historian-tag-data-calculating-runtime/27173>\
**Category:** General Discussion\
**Created:** [August 5, 2019, 6:09pm UTC](https://forum.inductiveautomation.com/t/historian-tag-data-calculating-runtime/27173 "2019-08-05T18:09:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mnoll](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mnoll/32/10303_2.png) [@mnoll](https://forum.inductiveautomation.com/u/mnoll)\
**Post date:** [August 5, 2019, 6:09pm UTC](https://forum.inductiveautomation.com/t/historian-tag-data-calculating-runtime/27173/1 "2019-08-05T18:09:13Z")

</div>

I am trying to generate some very basic OEE data for some machines that we are monitoring. We are pulling of about a dozen sensor values in real time, and I have determined that if one of the sensors is reading above a certain value, then the machine can be considered in a running state, and other wise this value is near zero. I would like to know how I can easily calculate on different intervals for each machine what the percentage of the time that it was “running”. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [August 5, 2019, 7:42pm UTC](https://forum.inductiveautomation.com/t/historian-tag-data-calculating-runtime/27173/2 "2019-08-05T19:42:57Z")

</div>

One way would be to use a calculated tag that’s zero/False when your sensor is below your value and some positive value or True when the sensor is above that value. Then a [tag calculation for Duration On](https://docs.inductiveautomation.com/display/DOC80/system.tag.queryTagHistory) will give you the number of seconds the tag was above zero.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [August 5, 2019, 7:46pm UTC](https://forum.inductiveautomation.com/t/historian-tag-data-calculating-runtime/27173/3 "2019-08-05T19:46:48Z")

</div>

Welcome to the forum @mnoll

I use a transaction group to log timestamps in a database based on changes on a run status tag. This query works well for binding to a pie chart.

```auto
SELECT Run_Status, SUM(TIMESTAMPDIFF(MINUTE, Start_Time, End_Time)) as Time 
FROM run_status_events 
WHERE Some Conditions
GROUP BY Run_Status

```
