# Getting the last stored value of tag

**URL:** <https://forum.inductiveautomation.com/t/getting-the-last-stored-value-of-tag/100890>\
**Category:** General Discussion\
**Created:** [January 14, 2025, 8:51pm UTC](https://forum.inductiveautomation.com/t/getting-the-last-stored-value-of-tag/100890 "2025-01-14T20:51:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marco\_alvarez](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@marco\_alvarez](https://forum.inductiveautomation.com/u/marco_alvarez)\
**Post date:** [January 14, 2025, 8:51pm UTC](https://forum.inductiveautomation.com/t/getting-the-last-stored-value-of-tag/100890/1 "2025-01-14T20:51:49Z")

</div>

Hi guys, I have a script that captures the last value stored in the historian. Most of the time it works fine, but sometimes it goes out of phase and starts returning not the last value, but an older one.

```python
tagPaths = "[default]xx/DB_statusTags/minute_write"
ds = system.tag.queryTagHistory(paths=[tagPaths], returnSize=1, noInterpolation=True,aggregationMode="LastValue")
value= ds.getValueAt(0, 1) # Get the value at row i, column j
paths = ["[default]xx/DB_statusTags/minute_read"]
system.tag.writeBlocking(paths, value)

```

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

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [January 14, 2025, 10:11pm UTC](https://forum.inductiveautomation.com/t/getting-the-last-stored-value-of-tag/100890/2 "2025-01-14T22:11:54Z")

</div>

Just a guess, but it sounds like a timing issue. For example, your script runs just before a tag value is logged, so it _ **was** _ the last value when the script ran, but not after the last history log.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 14, 2025, 10:17pm UTC](https://forum.inductiveautomation.com/t/getting-the-last-stored-value-of-tag/100890/3 "2025-01-14T22:17:13Z")

</div>

I think the Historian documentation is lacking in detail about how it works. When there's an analog deadband, for example, when does the new entry get saved? Is the current value saved and updated periodically if we're still in-band or does nothing get saved until we go out of band?

This, and the lack of interpolation and extrapolation at date-range boundaries makes the historian of limited use for many applications.

> **[Configuring Tag History | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/ignition-modules/tag-historian/configuring-tag-history#deadband-discrete-style-and-analog-compression)**
>
> In 8.1.17, the Tag Editor was redesigned to improve usability. The new Tag Editor now requires fewer clicks and keeps relevant tag information visible while modifying bindings, alarms, and event scripts.

---

<div class="post-metadata">

**Author:** ![marco\_alvarez](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@marco\_alvarez](https://forum.inductiveautomation.com/u/marco_alvarez)\
**Post date:** [January 14, 2025, 10:25pm UTC](https://forum.inductiveautomation.com/t/getting-the-last-stored-value-of-tag/100890/4 "2025-01-14T22:25:33Z")

</div>

I hope this help  
minute\_read

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/6/662964cc572de042b0773d902b890a7b4c907c76.png)  
minute write  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/1/014b19f83f109d353f35bf977c891b0a4de6ff97.png)

the script run every 1 minute, the value change every one minute, they go out of fase for 20-30 minutes. When they are different for 3 minutes I trigger the alarm. Most of the time the system run fine, but its failing a random times during the night.
