# system.historian.queryAggregatedPoints() per hour average?

**URL:** <https://forum.inductiveautomation.com/t/system-historian-queryaggregatedpoints-per-hour-average/111179>\
**Category:** Ignition\
**Tags:** ignition83\
**Created:** [October 3, 2025, 5:45pm UTC](https://forum.inductiveautomation.com/t/system-historian-queryaggregatedpoints-per-hour-average/111179 "2025-10-03T17:45:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![putnam3d](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@putnam3d](https://forum.inductiveautomation.com/u/putnam3d)\
**Post date:** [October 3, 2025, 5:45pm UTC](https://forum.inductiveautomation.com/t/system-historian-queryaggregatedpoints-per-hour-average/111179/1 "2025-10-03T17:45:59Z")

</div>

I’m experimenting with the new system.historian namespace and I’m curious how I could possibly use the function system.historian.queryAggregatedPoints() system function in order to query the tag historian and get the average value of a tag per hour over a specified time range, where each row of data returned contains a data point for the average value within each hour? I don’t see any interval parameters or sample by and can half get there using the returnSize.

Is there a key concept I am missing in relation to the system function system.historian.queryAggregatedPoints() ? or an example that shows a per hour average with a specific time range?

---

<div class="post-metadata">

**Author:** ![anjoroge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/anjoroge/32/6698_2.png) [@anjoroge](https://forum.inductiveautomation.com/u/anjoroge)\
**Post date:** [October 6, 2025, 5:37pm UTC](https://forum.inductiveautomation.com/t/system-historian-queryaggregatedpoints-per-hour-average/111179/2 "2025-10-06T17:37:14Z")

</div>

I seems like what you are trying to do can easly be achieved with the `system.tag.queryTagHistory().` Since it is generally used for historical tag data and includes parameters that allow for interval based aggregration. Some of the parameter it has are `internalHours` and `aggregationMode`.

> **[system.tag.queryTagHistory | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-queryTagHistory)**
>
> Issues a query to the Tag Historian.

---

<div class="post-metadata">

**Author:** ![Kurt.Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kurt.larson/32/6426_2.png) [@Kurt.Larson](https://forum.inductiveautomation.com/u/Kurt.Larson)\
**Post date:** [October 6, 2025, 6:15pm UTC](https://forum.inductiveautomation.com/t/system-historian-queryaggregatedpoints-per-hour-average/111179/3 "2025-10-06T18:15:07Z")

</div>

Here's an example. You'll need to calculate the hour intervals needed:

```python
import math 

end_date = system.date.now()
start_date = system.date.addDays(end_date, -1)

difference_in_seconds = system.date.secondsBetween(start_date, end_date)
total_hours = difference_in_seconds / 3600.0

hour_windows = math.ceil(total_hours)

paths = ['histprov:Historian:/prov:default:/tag:Ramp/Ramp0']
aggregates = ['Average']

result = system.historian.queryAggregatedPoints(paths=paths, startTime=start_date, endTime=end_date, aggregates=aggregates, returnSize=hour_windows)
for r in result: print r[0], r[1]
```

---

<div class="post-metadata">

**Author:** ![rberghammer](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rberghammer/32/7150_2.png) [@rberghammer](https://forum.inductiveautomation.com/u/rberghammer)\
**Post date:** [November 11, 2025, 9:06pm UTC](https://forum.inductiveautomation.com/t/system-historian-queryaggregatedpoints-per-hour-average/111179/4 "2025-11-11T21:06:09Z")

</div>

Should we be using system.tag.queryTagHistory() if it is being depreciated?

---

<div class="post-metadata">

**Author:** ![anjoroge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/anjoroge/32/6698_2.png) [@anjoroge](https://forum.inductiveautomation.com/u/anjoroge)\
**Post date:** [November 11, 2025, 10:26pm UTC](https://forum.inductiveautomation.com/t/system-historian-queryaggregatedpoints-per-hour-average/111179/5 "2025-11-11T22:26:10Z")

</div>

I don’t think there is anything wrong with using `system.tag.queryTaghistory()` but it would be preferred if you used the newer `system.historian.queryAggregatedPoints()`. Since the earlier is deprecated.
