# Making a kwh report

**URL:** <https://forum.inductiveautomation.com/t/making-a-kwh-report/87287>\
**Category:** Ignition\
**Created:** [March 13, 2024, 5:35pm UTC](https://forum.inductiveautomation.com/t/making-a-kwh-report/87287 "2024-03-13T17:35:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![O\_E](https://avatars.discourse-cdn.com/v4/letter/o/c57346/32.png) [@O\_E](https://forum.inductiveautomation.com/u/O_E)\
**Post date:** [March 13, 2024, 5:35pm UTC](https://forum.inductiveautomation.com/t/making-a-kwh-report/87287/1 "2024-03-13T17:35:32Z")

</div>

Hi

i am wondering what would be the best way of making a kwh report in Ignition Reportig ?

I have come as fare as getting a report to give me a table with logged numbers bewteene two given dates.

Where im getting stuck are if i have historical data on a Kwh(total) counter and i want to report hourly consumption betweene given dates how would i do that ?

I have not used SQL language before to be fair.

somthing similar to

hour - kwh(total counter) - kwh(Consumption)  
1 - 100  
2 - 120 - 20  
4 - 150 - 30  
5 - 150 - 0

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 13, 2024, 5:48pm UTC](https://forum.inductiveautomation.com/t/making-a-kwh-report/87287/2 "2024-03-13T17:48:59Z")

</div>

Ths may give you a start.

> [@Tag history difference over interval](https://forum.inductiveautomation.com/t/tag-history-difference-over-interval/48366/2):
>
> With the help of @JordanCClark (thanks, didn’t know about zip), I ended up with the below script. It will take a history tag (integer, float, double) and find the difference over hour intervals between a start and end date. Any value over 0 will be counted. You can rollover at any time, although your process may deem it necessary to only rollover if you aren’t running. You can then use this is a bar chart, for example, to show counts per hour over time. If the tag doesn’t exist, it should j…

---

<div class="post-metadata">

**Author:** ![O\_E](https://avatars.discourse-cdn.com/v4/letter/o/c57346/32.png) [@O\_E](https://forum.inductiveautomation.com/u/O_E)\
**Post date:** [March 13, 2024, 6:27pm UTC](https://forum.inductiveautomation.com/t/making-a-kwh-report/87287/3 "2024-03-13T18:27:24Z")

</div>

Thank you, it looks like this is exactly what i need.

Could you give me some pointers on how to implement/set it up in ignition ?

i have only used very basic scripting on components(buttons etc) in Ignition so fare

---

<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:** [March 13, 2024, 6:54pm UTC](https://forum.inductiveautomation.com/t/making-a-kwh-report/87287/4 "2024-03-13T18:54:26Z")

</div>

Make sure that you display 'kWh'. 'k' for kilo, 'W' for watt, as defined by SI. The hour isn't an SI unit so you can use your own preference for that but since 'H' is henries I'd avoid it. 'KWh' would be kelvin-watt-hours.  
Capitals matter (as they do in your post, cough, cough).

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [March 13, 2024, 9:15pm UTC](https://forum.inductiveautomation.com/t/making-a-kwh-report/87287/5 "2024-03-13T21:15:30Z")

</div>

You may also want to leverage the "intervalHours" parameter in the system.tag.queryTagHistory() function. Together with the "LastValue" or "Range" aggregate parameter, you can get either the running total of your counter or the difference between hours.

> **[system.tag.queryTagHistory | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-queryTagHistory)**
>
> Issues a query to the Tag Historian.
