# Best practice for tag calculating derivative (difference between values at 2 timestamps)

**URL:** <https://forum.inductiveautomation.com/t/best-practice-for-tag-calculating-derivative-difference-between-values-at-2-timestamps/54728>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [January 6, 2022, 3:44pm UTC](https://forum.inductiveautomation.com/t/best-practice-for-tag-calculating-derivative-difference-between-values-at-2-timestamps/54728 "2022-01-06T15:44:53Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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 6, 2022, 4:03pm UTC](https://forum.inductiveautomation.com/t/best-practice-for-tag-calculating-derivative-difference-between-values-at-2-timestamps/54728/2 "2022-01-06T16:03:21Z")

</div>

I would use my `objectScript()` expression function’s `state` dictionary to hold the last few samples of each tag in memory (with timestamps) and calculate from those. Best if delegated to a function in the global scripting project. If you are particular about accuracy at startup, you can populate empty state from the historian, then track tag change from there.

You’ll need this free module:

> **[Ignition Third-Party Module Showcase](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-simulation-aids)**
>
> Easily extend Ignition's core functionality with Third-Party Modules. The Module Showcase is a great place to find a solution that best meets your needs.

---

_[View the full topic](https://forum.inductiveautomation.com/t/best-practice-for-tag-calculating-derivative-difference-between-values-at-2-timestamps/54728)._
