# Multiple queryTagHistory result nulls at start and shift down data

**URL:** <https://forum.inductiveautomation.com/t/multiple-querytaghistory-result-nulls-at-start-and-shift-down-data/90211>\
**Category:** Ignition\
**Created:** [May 10, 2024, 7:23am UTC](https://forum.inductiveautomation.com/t/multiple-querytaghistory-result-nulls-at-start-and-shift-down-data/90211 "2024-05-10T07:23:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [May 10, 2024, 7:23am UTC](https://forum.inductiveautomation.com/t/multiple-querytaghistory-result-nulls-at-start-and-shift-down-data/90211/1 "2024-05-10T07:23:01Z")

</div>

Hello,  
I try to return the history data of multiple tags together with either history binding or `system.tag.queryTagHistory()` in As Stored Mode(returnSize = -1). All of those tags are stored in the database with the same timestamp.  
I even try to history data with` system.tag.storeTagHistory()` to force same t\_stamp.

```python
paths = ["[default]SIM/ramp 1", "[default]SIM/realistic", "[default]SIM/KV"]
dataset = system.tag.queryTagHistory(paths, startDate, endDate, aggregationMode = "LastValue", returnSize = -1)

```

The problem is the return dataset is started with nulls in the following order:  
One-time Null for the second tag in the paths  
Two times for the third tag in the paths  
Three times for the fourth tag in the paths  
And so on.. (n nulls for n+1 tags in the list)  
As shown below image the time stamps are repeating for every 3 rows (which is equal to the number of tags)  
Here I need to shift up the second tag one row and shift up the 3rd tag 2 times to make them sync together which extra load for every query.

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

So I wonder if is this a bug or if I did something wrong here to get this strange result.  
What should I do to get rid of shifting down the data?

---

<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:** [May 10, 2024, 8:18am UTC](https://forum.inductiveautomation.com/t/multiple-querytaghistory-result-nulls-at-start-and-shift-down-data/90211/2 "2024-05-10T08:18:03Z")

</div>

Display the t\_stamp as milliseconds and you will see that they are recorded at different times. The repeated values are interpolated.

The Historian uses a narrow table and does not give a nice way to convert to wide. I gave up and created my own wide tables where needed and record each tag simultaneously.

The only other option is to loop through using a script and returning all the rows before a larger t\_stamp change. Messy.

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [May 10, 2024, 8:34am UTC](https://forum.inductiveautomation.com/t/multiple-querytaghistory-result-nulls-at-start-and-shift-down-data/90211/3 "2024-05-10T08:34:47Z")

</div>

I put.SSS in a table to display mi-seconds and they are same, believe me.  
Also, I store those in system.tag.storeTagHistory() in script with same t\_stamp, so this is not the case.  
Also why there are null values at the start? Don't you agree this is a bug?(for Wide format)  
now I try to query them one by one (which is not efficient) and zip them together.

```python
	paths = [tagPath + "/lng"]
	lngDataset = system.tag.queryTagHistory(paths, startDate, endDate, aggregationMode = "LastValue", returnSize = -1)
	lngDataset = system.dataset.toPyDataSet(lngDataset)

	paths = [tagPath + "/lat"]	
	latDataset = system.tag.queryTagHistory(paths, startDate, endDate, aggregationMode = "LastValue", returnSize = -1)
	latDataset = system.dataset.toPyDataSet(latDataset)

	for lng, lat in zip(lngDataset, latDataset):
		coordinates.append([lng[1], lat[1]])

```

---

<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:** [May 10, 2024, 8:58am UTC](https://forum.inductiveautomation.com/t/multiple-querytaghistory-result-nulls-at-start-and-shift-down-data/90211/4 "2024-05-10T08:58:37Z")

</div>

> [@nader.chinichian](#):
>
> I put.SSS in a table to display mi-seconds and they are same, believe me.

I believe you!

> [@nader.chinichian](#):
>
> Don't you agree this is a bug?

I don't know, but the way it works is not obvious to the user and not well documented. I gave up on Historian except for long term data logging for diagnosis on Power Chart.

---

<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:** [May 10, 2024, 11:32am UTC](https://forum.inductiveautomation.com/t/multiple-querytaghistory-result-nulls-at-start-and-shift-down-data/90211/5 "2024-05-10T11:32:31Z")

</div>

Wide format is simply incompatible with "as stored". Use tall format and transform the result into separate lists (by grouping on tag path).
