# Reporting flow totals, issue with PLC data rollover

**URL:** <https://forum.inductiveautomation.com/t/reporting-flow-totals-issue-with-plc-data-rollover/105971>\
**Category:** Ignition\
**Created:** [May 7, 2025, 11:48am UTC](https://forum.inductiveautomation.com/t/reporting-flow-totals-issue-with-plc-data-rollover/105971 "2025-05-07T11:48:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Drum](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@Christopher\_Drum](https://forum.inductiveautomation.com/u/Christopher_Drum)\
**Post date:** [May 7, 2025, 11:48am UTC](https://forum.inductiveautomation.com/t/reporting-flow-totals-issue-with-plc-data-rollover/105971/1 "2025-05-07T11:48:25Z")

</div>

I ran into an issue with a customers flow total report. My issue is that the variable used in the PLC is only a 16 bit unsigned integer so the value rolls over every 2-3 days. The report was setup to use Aggregation mode Range with an interval of 24 hours. Report runs at the beginning of a new month and reports on the flow total for each day of the month so 12am - 12am.

The Range Aggregation mode is not accounting for rollover, it just reports on the absolute difference between the values recorded at each 24hr increment at 12am.

I tried other aggregation modes but nothing is working the way I needed it to.

Ignition is version 8.0.12

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [May 7, 2025, 1:00pm UTC](https://forum.inductiveautomation.com/t/reporting-flow-totals-issue-with-plc-data-rollover/105971/2 "2025-05-07T13:00:11Z")

</div>

Maybe this will be helpful,

> [@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:** ![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:** [May 7, 2025, 1:49pm UTC](https://forum.inductiveautomation.com/t/reporting-flow-totals-issue-with-plc-data-rollover/105971/3 "2025-05-07T13:49:11Z")

</div>

My approach was something like this:

- Create a new memory tag `allTimeBatchSum`.
- On your OPC cycle count tag add a script on the Value Changed event.

```python
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	"""
	Watch for the machine's counter being rolling over and, when it does, 
	add the rollover value to the All-Time cumulative counters.
	2023-06-03 @Transistor	
	"""
	currentCycles = currentValue.value # From PLC's resetting cycle counter
	prevCycles = previousValue.value # This memory tag.

	if currentCycles < prevCycles: # Batch counter has been reset.
		rollover = 65535 # or whatever
		paths = ["[.]allTimeBatchSum"]
		values = system.tag.readBlocking(paths)
		system.tag.writeBlocking(paths, [values[0].value + rollover]

```

- Now create an expression tag `totalMachineCycles` to sum the allTimeBatchSum with the current count. e.g.,  
`{[.]allTimeBatchSum} + {[.]MachineCountCycles}`
- Log this tag in your historian or whatever and you can now get the difference between any two timestamps very easily.

Note: I've adapted this script from my application and haven't tested it but it should give you a good idea how to go about it.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [May 7, 2025, 1:57pm UTC](https://forum.inductiveautomation.com/t/reporting-flow-totals-issue-with-plc-data-rollover/105971/4 "2025-05-07T13:57:09Z")

</div>

What happens if you download a program with "stale" data? This is rheorical. 🙂

---

<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:** [May 7, 2025, 2:19pm UTC](https://forum.inductiveautomation.com/t/reporting-flow-totals-issue-with-plc-data-rollover/105971/5 "2025-05-07T14:19:11Z")

</div>

> [@jlandwerlen](#):
>
> What happens if you download a program with "stale" data?

Don't!

On a practical note, you could get the last count from Ignition and load it back in automatically or manually. I've never done it.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [May 7, 2025, 2:20pm UTC](https://forum.inductiveautomation.com/t/reporting-flow-totals-issue-with-plc-data-rollover/105971/6 "2025-05-07T14:20:45Z")

</div>

A lot easier to reset on first scan and let Ignition handle the rest. Just my two pennies.

---

<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:** [May 7, 2025, 2:22pm UTC](https://forum.inductiveautomation.com/t/reporting-flow-totals-issue-with-plc-data-rollover/105971/7 "2025-05-07T14:22:19Z")

</div>

OK, but you'd have to modify my script not to add in 65535 but get the last count value from somewhere.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [May 7, 2025, 2:25pm UTC](https://forum.inductiveautomation.com/t/reporting-flow-totals-issue-with-plc-data-rollover/105971/8 "2025-05-07T14:25:52Z")

</div>

I'm not using your script 🙂
