Tag Calculation (Current Value - Previous Value)

I have 300 Energy tags with history enabled that need calculations on it.
My values are being stored every 60 mins. I want my value calculated as
Current Value- Previous Value.
In another post on the forum the solution for 3 tags (1. Original, 2.Previous value, 3. Derived tag with calculated value) works. But this solution is not effective for 300 tags or more. Creating 3 tags for each energy tag will give me (3 x 300) = 900 tags for my system is way too much
Is there a way a script or any other solution would work here?

You could create your tag for current, and add a change script on it then write that value to a memory tag called whatever.
Put these in some UDTs and configuring 300 copies won't take very long.

1 Like

900 tags is not a large number of tags overall. Yes, it would take some time to create 900 tags. However, you can do this with a UDT and save some time.

Are the tag names formatted in a predictable way?

What is the use case? Are you displaying the difference somewhere?

1 Like

What kind of change scripts in UDT? Making derived tags?

Yes my tags are formatted in a predictable way , I need final kWh reading on my dashboard.
I don't understand the UDT point. Could you elaborate.

Create a UDT to hold your current and previous tags. You don't need the derived value as a tag unless that is what you are recording historically. Otherwise, just do the calculation at display time.

Once you've created the UDT definition, use the Multi-Instance Wizard to quickly create all of your needed tags.

3 Likes

Create a UDT with a couple of parameters. Generate the OPC path based on those parameters.

What do your tag paths look like?

1 Like

You can right click the tag, and add a change script. This will just be a bit of python code to do the writing.
Just make sure to use system.tag.writeAsync() as that will cause less potential tag threading issues.