Logging totalizer* every 15 minutes + report

So I need to log data every 15 minutes off a flowmeter.
I need to grab GPM, Grand Total, Flow (gallons for last 15 minutes.) All in a PLC.

System is 7.8.5 and does have transaction module but not reporting module.

So every 15 minutes I can grab the GPM and the grand total. Flow would just be current grand total - last grand total.

I'm thinking I can use a gateway script to record every 15 minutes and save to DB. Then use system.dataset.exportExcel to toss the recordings for the last 24 hours into a folder on the server. And then possibly prune the last 24 because its already been recorded.
If possible I'd like to limit the amount of files in the folder. and name with date for ease of use.

looking for best practices or better ideas.

Data would need to look like this in the report.

Date|Time (HH:MM:SS)|Totalizer read (Gallons)|Total Flow (Gallons)|Flow Rate (GPM)|
| --- | --- | --- | --- | --- |
|June 1|00:00:00|651,185,326|786|52|
|June 1|00:15:00|651,186,177|851|56|
|June 1|00:30:00|651,187,653|1476|98.4|
|June 1|00:45:00|651,188,888|1235|82|

Can I do a calculation previous grand total minus current in the transaction group? Or would this need be a tag change script writing to a new tag. would I need to offset it by a min to avoid a race condition?

You could use a query expression item to get the last row in the table, but it would probably be more efficient to use a LEAD or LAG in the query you use to generate the report.


Thanks, thats a good idea. I just used a counter in the PLC in the meantime.