Previous Values

I’m very new to the system…

I need to get the differnce between the current value and previous value.

thank you

Are you using Perspective or Vision?

Using a property change script in Perspective:

    # make sure the indentation is correct if copying this code

    # This component has a custom property I created with a key of "difference" which stores 
    # the difference between the new value and the old value.
	if previousValue and previousValue.value:
		self.custom.difference = currentValue.value - previousValue.value

Vision

What would be prefered?

# make sure the indentation is correct if copying this code

# This component has a custom property I created with a key of "difference" which stores 
# the difference between the new value and the old value.
if event.propertyName == 'intValue':
	event.source.difference = event.newValue - event.oldValue
1 Like

This needs a little more context to give a useful answer:

  • current/previous value of what exactly? I presume a tag?
  • how and where do you want to see this difference? E.g. Do you want another tag to hold this value?

It depends what you’re doing. What’s your application? You need to use vision if you want to interact with the client’s filesystem, but I would tend to recommend perspective otherwise as it’s newer and is where most development effort is being spent

Yes a tag.
A new tag would probably make the most sense.

Currently it is mainly for a simple dashboarding application where monitoring takes places.So no real action needs to take place other some simple navigation and may be some reporting.

So I think for now i’ll start with perspective and go from there.

Sorry for the delay, but if you want to track the difference between a tag’s value and its previous value in a tag, I would actually store the previous value in another tag, and then use an expression tag to calc the difference.

  1. Create a new tag in the same directory called ‘Previous Value’ (as an example)
  2. In the current value tag’s config, configure a Tag Event Script on the Value Changed event :
if not initialChange:
    prevTagPath = "[.]Previous Value"
    system.tag.writeAsync([prevTagPath], [previousValue.value])
  1. Create a new expression tag with the expression:
{[.]Previous Value} - {[.]Current Value}