# How to get initial value from queryTagHistory

**URL:** <https://forum.inductiveautomation.com/t/how-to-get-initial-value-from-querytaghistory/62179>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [July 21, 2022, 9:23pm UTC](https://forum.inductiveautomation.com/t/how-to-get-initial-value-from-querytaghistory/62179 "2022-07-21T21:23:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fleclerc](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/fleclerc/32/20480_2.png) [@fleclerc](https://forum.inductiveautomation.com/u/fleclerc)\
**Post date:** [July 21, 2022, 9:23pm UTC](https://forum.inductiveautomation.com/t/how-to-get-initial-value-from-querytaghistory/62179/1 "2022-07-21T21:23:36Z")

</div>

When using system.tag.queryTagHistory, I have NULL as value until there is a change for that tag.  
How can I get the initial value of each tag at start time?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/9/39e09e3c3e8ba34a9372d3d2e906d12f30235901.png)

In the picture, before Mode changes to MODE\_AUTOMATIC it was probably at MODE\_MANUAL, but I cannot see it.

It should be as simple as ‘return the closest value recorded before start time’.  
Or is there a function to get the a value at a specific time in history, instead of using a date range?

---

<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:** [July 22, 2022, 12:06pm UTC](https://forum.inductiveautomation.com/t/how-to-get-initial-value-from-querytaghistory/62179/2 "2022-07-22T12:06:41Z")

</div>

Did you try setting the **includeBoundingValues** flag to True?

---

<div class="post-metadata">

**Author:** ![fleclerc](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/fleclerc/32/20480_2.png) [@fleclerc](https://forum.inductiveautomation.com/u/fleclerc)\
**Post date:** [July 22, 2022, 12:22pm UTC](https://forum.inductiveautomation.com/t/how-to-get-initial-value-from-querytaghistory/62179/3 "2022-07-22T12:22:08Z")

</div>

Yes I did… I looked at the documentation and was expecting **includeBoundingValues** to solve that issue.

---

<div class="post-metadata">

**Author:** ![fleclerc](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/fleclerc/32/20480_2.png) [@fleclerc](https://forum.inductiveautomation.com/u/fleclerc)\
**Post date:** [July 22, 2022, 12:30pm UTC](https://forum.inductiveautomation.com/t/how-to-get-initial-value-from-querytaghistory/62179/4 "2022-07-22T12:30:32Z")

</div>

There is Tag History Bindings in Perspective, it seems to work as expected if I ask for one data point per tag with a narrow date range. But I don’t know how to do the same in script.

[https://docs.inductiveautomation.com/display/DOC80/Tag+History+Bindings+in+Perspective](https://docs.inductiveautomation.com/display/DOC80/Tag+History+Bindings+in+Perspective)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 22, 2022, 12:36pm UTC](https://forum.inductiveautomation.com/t/how-to-get-initial-value-from-querytaghistory/62179/5 "2022-07-22T12:36:05Z")

</div>

> [@fleclerc](#):
>
> There is Tag History Bindings in Perspective, it seems to work as expected if I ask for one data point per tag with a narrow date range

What is a “narrow” date range for your application?

How was this binding configured and what did the script look like that you used to try and replicate it?

---

<div class="post-metadata">

**Author:** ![fleclerc](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/fleclerc/32/20480_2.png) [@fleclerc](https://forum.inductiveautomation.com/u/fleclerc)\
**Post date:** [July 22, 2022, 1:29pm UTC](https://forum.inductiveautomation.com/t/how-to-get-initial-value-from-querytaghistory/62179/6 "2022-07-22T13:29:36Z")

</div>

When testing if I can get the last value in history for a specific time, I used a Tag History Binding in Perspective with a time range of zero (same Start Date and End Date) and 1 as Point Count.

About the script calling _system.tag.queryTagHistory_ with NULL value until there is a tag change; the default range is 1 hours customisable by the user.

```auto
system.tag.queryTagHistory(paths=PathList, startDate=StartTime, endDate=EndTime, returnSize = -1, returnFormat='Wide', includeBoundingValues= True, ignoreBadQuality=True, noInterpolation=True)

```
