# Get corresponding timestamp to a specific value in a trend

**URL:** <https://forum.inductiveautomation.com/t/get-corresponding-timestamp-to-a-specific-value-in-a-trend/92207>\
**Category:** Ignition\
**Created:** [June 21, 2024, 1:21pm UTC](https://forum.inductiveautomation.com/t/get-corresponding-timestamp-to-a-specific-value-in-a-trend/92207 "2024-06-21T13:21:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastien.rancourt](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien.rancourt/32/11344_2.png) [@sebastien.rancourt](https://forum.inductiveautomation.com/u/sebastien.rancourt)\
**Post date:** [June 21, 2024, 1:21pm UTC](https://forum.inductiveautomation.com/t/get-corresponding-timestamp-to-a-specific-value-in-a-trend/92207/1 "2024-06-21T13:21:36Z")

</div>

Good day,

I would like to know if it is possible to get the timestamp related to a value in a trend that was found after I query for a maximum value between a defined period of time.

system.tag.queryTagHistory(paths=["tag1"],startDate=s,endDate=e,returnSize=d,aggregationMode='Maximum')

By default, this function returns a timestamp and a value (assuming the returnSize is set to 1), but the timestamp is always equals to the startDate and I would like to know at what time this maximum was reached in that period.

Best regards,

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 22, 2024, 9:06am UTC](https://forum.inductiveautomation.com/t/get-corresponding-timestamp-to-a-specific-value-in-a-trend/92207/2 "2024-06-22T09:06:28Z")

</div>

I'm not sure you can do that using that function.  
But it should be easy enough to query the data "as stored" for a time window, then use python's [`max` with its `key` argument](https://docs.python.org/3/library/functions.html#max) to get the timestamp associated with the maximum value.

You'll just have to convert the dataset `queryTagHistory` returns into an iterable. `system.dataset.toPyDataSet` should be enough:  
something like

```python
ds = system.tag.queryTagHistory(...)
max_ts, max_val = max(system.dataset.toPyDataSet(ds), key=lambda row: row[1])

```

this _ **should** _ give you what you want but I can't test it now.  
If not, it shouldn't be too far off.

You can also try `system.tag.queryTagCalculations`, maybe it will return the timestamp of the actual max ? It's been a while since I've used it.
