# \[Bug?\]: system.tag.queryTagHistory data issue

**URL:** <https://forum.inductiveautomation.com/t/bug-system-tag-querytaghistory-data-issue/64872>\
**Category:** Ignition\
**Created:** [October 5, 2022, 11:57pm UTC](https://forum.inductiveautomation.com/t/bug-system-tag-querytaghistory-data-issue/64872 "2022-10-05T23:57:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![srb](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@srb](https://forum.inductiveautomation.com/u/srb)\
**Post date:** [October 5, 2022, 11:57pm UTC](https://forum.inductiveautomation.com/t/bug-system-tag-querytaghistory-data-issue/64872/1 "2022-10-05T23:57:39Z")

</div>

I'm trying to get a tag's value at 9:00 AM everyday over the past month - say Sept 1st to Oct 1st.

I have two test queries. Query 1 is showing me the values at 9 AM (returnSize = 30) and Query 2 shows me the raw data with aggregationMode = LastValue and returnSize = -1.

I'm noticing the following behavior:

Query 1 Sept 1 Value - **doesn't match** - Query 2 Sept 1 Value  
=-------------------------------------------------------------------------------=  
Query 1 Sept 1 Value - **matches** - Query 2 Sept 2 Value  
Query 1 Sept 2 Value - **matches** - Query 2 Sept 3 Value  
....and so on as shown below

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

I'm not sure what I'm missing.

Query 1 is shown below.

```auto
import time 
from java.text import SimpleDateFormat

endTimestr = "2022-10-01 09:00:00"

inputFormat=SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
endTime=SimpleDateFormat.parse(inputFormat,endTimestr)
startTime = system.date.addMonths(endTime, -1)

path1 = "[Default]AAA/BBB/CCC/Gas Meter Temperature"

dataSet = system.tag.queryTagHistory(paths=[path1], startDate=startTime, endDate=endTime, returnSize=30, 
aggregationMode="LastValue", returnFormat='Wide', noInterpolation=True)
for i in range(dataSet.getRowCount()):
	print dataSet.getValueAt(i,0)
	print dataSet.getValueAt(i,1)

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [October 9, 2022, 12:43am UTC](https://forum.inductiveautomation.com/t/bug-system-tag-querytaghistory-data-issue/64872/2 "2022-10-09T00:43:16Z")

</div>

I was able to reproduce your result using power tables, and it really does seem like a bug. When I use `system.tag.queryTagHistory` with a `returnSize` parameter of anything other than the default -1, my resultant columns are misaligned by 1 value:

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

In the above example, the table on the left has a return size of 10, and the table on the right has the default return size.

Query 1 code:  
`system.tag.queryTagHistory(paths=[path1], startDate=startTime, endDate=endTime, returnSize=10, aggregationMode="LastValue", returnFormat='Wide', noInterpolation=True)`

Query 2 code:  
`system.tag.queryTagHistory(paths=[path1], startDate=startTime, endDate=endTime, returnSize=-1, aggregationMode="LastValue", returnFormat='Wide', noInterpolation=True)`

---

<div class="post-metadata">

**Author:** ![srb](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@srb](https://forum.inductiveautomation.com/u/srb)\
**Post date:** [October 9, 2022, 12:50pm UTC](https://forum.inductiveautomation.com/t/bug-system-tag-querytaghistory-data-issue/64872/3 "2022-10-09T12:50:16Z")

</div>

Thanks, I'm a bit confused as well.

---

<div class="post-metadata">

**Author:** ![srb](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@srb](https://forum.inductiveautomation.com/u/srb)\
**Post date:** [October 17, 2022, 2:41pm UTC](https://forum.inductiveautomation.com/t/bug-system-tag-querytaghistory-data-issue/64872/4 "2022-10-17T14:41:55Z")

</div>

Bump. Any help/explanation regarding this behavior please?

---

<div class="post-metadata">

**Author:** ![nideyijuyidong](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@nideyijuyidong](https://forum.inductiveautomation.com/u/nideyijuyidong)\
**Post date:** [October 17, 2022, 2:48pm UTC](https://forum.inductiveautomation.com/t/bug-system-tag-querytaghistory-data-issue/64872/5 "2022-10-17T14:48:57Z")

</div>

Build your own SQL script, query the database manually.  
I tried that for weeks.😅  
queryTagHistory function does have flaws.

---

<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:** [October 17, 2022, 4:38pm UTC](https://forum.inductiveautomation.com/t/bug-system-tag-querytaghistory-data-issue/64872/6 "2022-10-17T16:38:03Z")

</div>

> [@srb](#):
>
> Bump. Any help/explanation regarding this behavior please?

If you want an official answer, you need to contact [Support](https://support.inductiveautomation.com). This forum is not an official support venue.

---

<div class="post-metadata">

**Author:** ![srb](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@srb](https://forum.inductiveautomation.com/u/srb)\
**Post date:** [October 17, 2022, 5:28pm UTC](https://forum.inductiveautomation.com/t/bug-system-tag-querytaghistory-data-issue/64872/7 "2022-10-17T17:28:56Z")

</div>

Ended up doing something similar, thanks.
