# Previous Values

**URL:** <https://forum.inductiveautomation.com/t/previous-values/46542>\
**Category:** Ignition\
**Created:** [May 10, 2021, 4:10pm UTC](https://forum.inductiveautomation.com/t/previous-values/46542 "2021-05-10T16:10:24Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdooley](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@mdooley](https://forum.inductiveautomation.com/u/mdooley)\
**Post date:** [May 10, 2021, 4:10pm UTC](https://forum.inductiveautomation.com/t/previous-values/46542/1 "2021-05-10T16:10:24Z")

</div>

I’m very new to the system…

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

thank you

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [May 10, 2021, 4:34pm UTC](https://forum.inductiveautomation.com/t/previous-values/46542/2 "2021-05-10T16:34:27Z")

</div>

Are you using Perspective or Vision?

Using a property change script in Perspective:

```auto
    # 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

```

---

<div class="post-metadata">

**Author:** ![mdooley](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@mdooley](https://forum.inductiveautomation.com/u/mdooley)\
**Post date:** [May 10, 2021, 5:10pm UTC](https://forum.inductiveautomation.com/t/previous-values/46542/3 "2021-05-10T17:10:32Z")

</div>

Vision

What would be prefered?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [May 10, 2021, 6:13pm UTC](https://forum.inductiveautomation.com/t/previous-values/46542/4 "2021-05-10T18:13:29Z")

</div>

```auto
# 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

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 11, 2021, 3:20am UTC](https://forum.inductiveautomation.com/t/previous-values/46542/5 "2021-05-11T03:20:31Z")

</div>

> [@mdooley](#):
>
> current value and previous value

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?

> [@mdooley](#):
>
> Vision
> 
> What would be prefered?

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

---

<div class="post-metadata">

**Author:** ![mdooley](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@mdooley](https://forum.inductiveautomation.com/u/mdooley)\
**Post date:** [May 11, 2021, 10:45am UTC](https://forum.inductiveautomation.com/t/previous-values/46542/6 "2021-05-11T10:45:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 18, 2021, 2:32am UTC](https://forum.inductiveautomation.com/t/previous-values/46542/7 "2021-05-18T02:32:18Z")

</div>

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 :

```auto
if not initialChange:
    prevTagPath = "[.]Previous Value"
    system.tag.writeAsync([prevTagPath], [previousValue.value])

```

1. Create a new expression tag with the expression:

```auto
{[.]Previous Value} - {[.]Current Value}

```

---

<div class="post-metadata">

**Author:** ![Vinodhini\_N](https://avatars.discourse-cdn.com/v4/letter/v/65b543/32.png) [@Vinodhini\_N](https://forum.inductiveautomation.com/u/Vinodhini_N)\
**Post date:** [January 9, 2024, 12:17pm UTC](https://forum.inductiveautomation.com/t/previous-values/46542/8 "2024-01-09T12:17:47Z")

</div>

Difference in previous value time and current value time? If the value is same more than 30 minutes should come a message that machine is downtime? how it is possible?

---

<div class="post-metadata">

**Author:** ![Vinodhini\_N](https://avatars.discourse-cdn.com/v4/letter/v/65b543/32.png) [@Vinodhini\_N](https://forum.inductiveautomation.com/u/Vinodhini_N)\
**Post date:** [January 9, 2024, 12:18pm UTC](https://forum.inductiveautomation.com/t/previous-values/46542/9 "2024-01-09T12:18:25Z")

</div>

How to bind this for visible property?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [January 9, 2024, 12:44pm UTC](https://forum.inductiveautomation.com/t/previous-values/46542/10 "2024-01-09T12:44:43Z")

</div>

> [@Vinodhini\_N](#):
>
> Difference in previous value time and current value time?

Note that this is off topic of the original post, and should be in its own thread.  
But to anser your question:

I would make an expression tag with something like:

```auto
minutesBetween({[.]path/to/tag.Timestamp}, now()) >= 30

```

then bind the visibility to the expression tag.

---

<div class="post-metadata">

**Author:** ![Vinodhini\_N](https://avatars.discourse-cdn.com/v4/letter/v/65b543/32.png) [@Vinodhini\_N](https://forum.inductiveautomation.com/u/Vinodhini_N)\
**Post date:** [January 9, 2024, 1:14pm UTC](https://forum.inductiveautomation.com/t/previous-values/46542/11 "2024-01-09T13:14:46Z")

</div>

if the current value and previous value is same more than 30 minutes . It should give a message that machine is downtime in a visible property binding for icon.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [January 9, 2024, 1:16pm UTC](https://forum.inductiveautomation.com/t/previous-values/46542/12 "2024-01-09T13:16:55Z")

</div>

If the value is the same the timestamp won't change.

---

<div class="post-metadata">

**Author:** ![Vinodhini\_N](https://avatars.discourse-cdn.com/v4/letter/v/65b543/32.png) [@Vinodhini\_N](https://forum.inductiveautomation.com/u/Vinodhini_N)\
**Post date:** [January 9, 2024, 1:33pm UTC](https://forum.inductiveautomation.com/t/previous-values/46542/13 "2024-01-09T13:33:24Z")

</div>

i am not asking about timestamp , i just asking the time difference if between 30 minutes the value is same it should say some message .

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 9, 2024, 1:38pm UTC](https://forum.inductiveautomation.com/t/previous-values/46542/14 "2024-01-09T13:38:53Z")

</div>

But to make that happen, something needs to _ **check** _ regularly, because the **lack of change** itself produces no events you could use. You need some _other_ event, like a polling `now()` expression, to cause your logic to evaluate.
