# How to calculate machine total hours and working hours using the tag history?

**URL:** <https://forum.inductiveautomation.com/t/how-to-calculate-machine-total-hours-and-working-hours-using-the-tag-history/93596>\
**Category:** Ignition\
**Tags:** ignition81, vision\
**Created:** [July 23, 2024, 10:42am UTC](https://forum.inductiveautomation.com/t/how-to-calculate-machine-total-hours-and-working-hours-using-the-tag-history/93596 "2024-07-23T10:42:41Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 25, 2024, 11:17am UTC](https://forum.inductiveautomation.com/t/how-to-calculate-machine-total-hours-and-working-hours-using-the-tag-history/93596/11 "2024-07-25T11:17:29Z")

</div>

You've posted your code as a quotation. You should have posted it as \</\> preformatted text. See [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).

I (and many others) gave up on tag history for things like hourly and daily reports. The historian doesn't inter/extrapolate to give you the edge count values. e.g., If you have a count value for 09:50 and one for 10:05 and ask for an aggregate function of 10:00 to 11:00 it will start its calculations on the 10:05 value. If you tried to manipulate the data by script to generate the 10:00 value you'd have the problem of how far back to go in history to ensure you got the previous value.

From my response to [https://forum.inductiveautomation.com/t/includeboundingvalues-not-working/90821:](https://forum.inductiveautomation.com/t/includeboundingvalues-not-working/90821:)

> I found Historian OK for general trending and useful for checking back on what happened at a certain time. For anything like production reports I recommend doing your own history. We logged each machine with a gateway script running on the hour and every 15 minutes as well as on status change of the "running" tag. With columns for t\_stamp, running, cycle count1, good parts count, SKU (recipe) and FirstOutAlarm we were able to generate excellent historical and realtime views.  
> 1 A never-resetting counter.

More discussion: [Save machine count on each change of run status - #16 by josborn](https://forum.inductiveautomation.com/t/save-machine-count-on-each-change-of-run-status/58492/16).

Tag change scripting: [Script about calculate the cumulative downtime - #25 by Transistor](https://forum.inductiveautomation.com/t/script-about-calculate-the-cumulative-downtime/82940/25).

If you do this and also scheduled logging on the hour or every 15 minutes using gateway scheduled events then the SQL and reporting for any interval becomes very simple.

---

_[View the full topic](https://forum.inductiveautomation.com/t/how-to-calculate-machine-total-hours-and-working-hours-using-the-tag-history/93596)._
