# How to access currentValue and previousValue from value change script

**URL:** <https://forum.inductiveautomation.com/t/how-to-access-currentvalue-and-previousvalue-from-value-change-script/91372>\
**Category:** Ignition\
**Created:** [June 4, 2024, 8:20pm UTC](https://forum.inductiveautomation.com/t/how-to-access-currentvalue-and-previousvalue-from-value-change-script/91372 "2024-06-04T20:20:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [June 4, 2024, 8:20pm UTC](https://forum.inductiveautomation.com/t/how-to-access-currentvalue-and-previousvalue-from-value-change-script/91372/1 "2024-06-04T20:20:23Z")

</div>

I have a dataset tag with two columns, t\_stamp and weight. It is 120 rows long. I want to be able to determine if the current value, in this case row 120, is greater than the previous value, in this case row 119. I want to only compare the weights.

Here is the screenshot of the bottom of dataset. Again the last row is the latest data.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/f/1f283325de4b4314112356b2e97847fe40d5931e.png)

Here is the screenshot of my thoughts on accessing the current and previous value

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/6/d6426eb56fa4139bb7d49e18e048e61469b6e38d.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 4, 2024, 8:24pm UTC](https://forum.inductiveautomation.com/t/how-to-access-currentvalue-and-previousvalue-from-value-change-script/91372/2 "2024-06-04T20:24:23Z")

</div>

Both values will be the entire dataset at that point in time, not a "delta". So you will have to explicitly ask for the last row (as in `dataset.rowCount - 1`) if your process in fact guarantees that the last row will be the most recently updated.

---

<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:** [June 4, 2024, 8:29pm UTC](https://forum.inductiveautomation.com/t/how-to-access-currentvalue-and-previousvalue-from-value-change-script/91372/3 "2024-06-04T20:29:26Z")

</div>

> [@paul-griffith](#):
>
> if your process in fact guarantees that the last row will be the most recently updated.

He's presumably using my recorder, so yes, it is.

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [June 4, 2024, 8:33pm UTC](https://forum.inductiveautomation.com/t/how-to-access-currentvalue-and-previousvalue-from-value-change-script/91372/4 "2024-06-04T20:33:10Z")

</div>

Haha, you are correct

---

<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:** [June 4, 2024, 10:41pm UTC](https://forum.inductiveautomation.com/t/how-to-access-currentvalue-and-previousvalue-from-value-change-script/91372/5 "2024-06-04T22:41:45Z")

</div>

I recommend an expression tag (in event driven mode) in the folder adjacent to the recorder tag, with this:

```python
transform(
	{[.]recordertag},
	transform(
		len(value()),
		if(
			value() > 1,
			value(1)[value()-1, 'weight'] - value(1)[value()-2, 'weight'],
			0.0
		)
	)
)

```

No script.

If you want to be really precise, use the inverse delta milliseconds of the `t_stamp` column to adjust for value delivery clock skew. (Probably not stable for adjacent samples, but should be really good across multiple samples.)
