# Script Averaging Calculation

**URL:** <https://forum.inductiveautomation.com/t/script-averaging-calculation/113217>\
**Category:** Ignition\
**Created:** [January 12, 2026, 5:58pm UTC](https://forum.inductiveautomation.com/t/script-averaging-calculation/113217 "2026-01-12T17:58:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bigtalljv](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@Bigtalljv](https://forum.inductiveautomation.com/u/Bigtalljv)\
**Post date:** [January 12, 2026, 5:58pm UTC](https://forum.inductiveautomation.com/t/script-averaging-calculation/113217/1 "2026-01-12T17:58:41Z")

</div>

hi,

I am trying to use some scripting, but I don’t actually know Python, I am more of a scriptkiddie, I can copy scripts I find and modify it enough to usually get where I need to.

I am trying to get an average of flows from 3 hour blocks of time. I have this script running on a tag binding, and it seems to work correctly, I get a dataset that has 5 minute datapoints that I want from yesterday between midnight and 3am.

```python
paths = ['[default]/ST25/_25_FI_110X_Total']
    now = system.date.now()
    previousDay = system.date.addDays(now, -1)
    time_midnight_previous_day =system.date.midnight(previousDay)
    startDate = time_midnight_previous_day
    endDate = system.date.addHours(startDate, 3)
    dataSetDay1=system.tag.queryTagHistory(paths=paths, startDate=startDate, endDate=endDate, aggregationMode = 'SimpleAverage', intervalMinutes = 5, returnFormat='Wide')
    return dataSetDay1

```

I then tried an additional expression:

mean({this.props.params.Day1}, "ST25/\_25\_FI\_110X\_Total")

and it seemed to work initially but now I am getting random “Data Quality: Bad\_Stale”

There seems to be a way to get the average in Python but I don’t understand exactly how that needs to be written. Or is there a better option?

Thanks

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [January 12, 2026, 7:12pm UTC](https://forum.inductiveautomation.com/t/script-averaging-calculation/113217/2 "2026-01-12T19:12:24Z")

</div>

I would use queryTagCalculations instead of queryTagHistory

[system.tag.queryTagCalculations | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-queryTagCalculations)

---

<div class="post-metadata">

**Author:** ![Bigtalljv](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@Bigtalljv](https://forum.inductiveautomation.com/u/Bigtalljv)\
**Post date:** [January 12, 2026, 8:10pm UTC](https://forum.inductiveautomation.com/t/script-averaging-calculation/113217/3 "2026-01-12T20:10:41Z")

</div>

Thanks,

I guess that does what I wanted in 1 step. I was able to get it working with this:

```python
    now = system.date.now()
    previousDay = system.date.addDays(now, -1)
    time_3am_previous_day = system.date.setTime(previousDay, 3, 0, 0)
    startDate = time_3am_previous_day
    endDate = system.date.addHours(startDate, 3)    
    
    data = system.tag.queryTagCalculations(
    paths=['[default]ST25/_25_FI_110X_Total'],
    calculations=['Average'],
    startDate=startDate,
    endDate=endDate
)
    return data.getValueAt(0,1)

```
