# Issue with PLC Tag Count Logic – Unexpected Raw Value in Hourly/Daily Counts

**URL:** <https://forum.inductiveautomation.com/t/issue-with-plc-tag-count-logic-unexpected-raw-value-in-hourly-daily-counts/106785>\
**Category:** Ignition\
**Created:** [May 28, 2025, 5:55pm UTC](https://forum.inductiveautomation.com/t/issue-with-plc-tag-count-logic-unexpected-raw-value-in-hourly-daily-counts/106785 "2025-05-28T17:55:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raghavendra\_Praneeth](https://avatars.discourse-cdn.com/v4/letter/r/87869e/32.png) [@Raghavendra\_Praneeth](https://forum.inductiveautomation.com/u/Raghavendra_Praneeth)\
**Post date:** [May 28, 2025, 5:55pm UTC](https://forum.inductiveautomation.com/t/issue-with-plc-tag-count-logic-unexpected-raw-value-in-hourly-daily-counts/106785/1 "2025-05-28T17:55:05Z")

</div>

Hello,  
Currently, I have a setup where I am reading some tag information from the PLC, such as scanner statistics. For each tag, I have a _Value Changed_ script where I count the change in tag value, as shown in the image below:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/a/9aa6fa01c1e92554fd5004e5a24a7f11d735e52b.png)

The `HourlyCount` is reset every 30 minutes, and the `DailyCount` is reset every day at 12:00 AM. I use a gateway script to reset these values. Additionally, based on the PLC's local time, the tag values themselves are sometimes reset to `0`.

The issue I'm facing is that occasionally, the `HourlyCount` and `DailyCount` are taking the raw value of the PLC tag(where Hourly Count is 12345678) instead of calculating the increment between the previous and current values. Normally, the count should increment by 1, as the PLC tag value typically increases by 1.

Is there anything wrong with this logic?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 28, 2025, 7:14pm UTC](https://forum.inductiveautomation.com/t/issue-with-plc-tag-count-logic-unexpected-raw-value-in-hourly-daily-counts/106785/2 "2025-05-28T19:14:48Z")

</div>

How many tags have this same or similar script?

---

<div class="post-metadata">

**Author:** ![Raghavendra\_Praneeth](https://avatars.discourse-cdn.com/v4/letter/r/87869e/32.png) [@Raghavendra\_Praneeth](https://forum.inductiveautomation.com/u/Raghavendra_Praneeth)\
**Post date:** [May 28, 2025, 7:56pm UTC](https://forum.inductiveautomation.com/t/issue-with-plc-tag-count-logic-unexpected-raw-value-in-hourly-daily-counts/106785/3 "2025-05-28T19:56:29Z")

</div>

This is the UDT and is used in many places

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 28, 2025, 8:40pm UTC](https://forum.inductiveautomation.com/t/issue-with-plc-tag-count-logic-unexpected-raw-value-in-hourly-daily-counts/106785/4 "2025-05-28T20:40:05Z")

</div>

You have 4 blocking calls in a value change script. Value change scripts should execute in single digit ms. On top of that, value change scripts execute in limited thread pool of 3 for all change events across the gateway.

It wouldn’t surprise me if you’re running into the queue limit.

This script should probably be a gateway tag change event, that is generic enough to handle any UDT with the proper structure.

At a minimum you should combine the reads and writes into single calls.

---

<div class="post-metadata">

**Author:** ![jrusso](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jrusso](https://forum.inductiveautomation.com/u/jrusso)\
**Post date:** [May 28, 2025, 8:44pm UTC](https://forum.inductiveautomation.com/t/issue-with-plc-tag-count-logic-unexpected-raw-value-in-hourly-daily-counts/106785/5 "2025-05-28T20:44:49Z")

</div>

This might not be the answer you're looking for, but stuff like this should really be done in the PLC. Way simpler to keep the logic in the PLC with a totalizer
