# Downsampling Historic Tags on Average for Current Month

**URL:** <https://forum.inductiveautomation.com/t/downsampling-historic-tags-on-average-for-current-month/86291>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [February 23, 2024, 8:20pm UTC](https://forum.inductiveautomation.com/t/downsampling-historic-tags-on-average-for-current-month/86291 "2024-02-23T20:20:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![D\_S](https://avatars.discourse-cdn.com/v4/letter/d/2bfe46/32.png) [@D\_S](https://forum.inductiveautomation.com/u/D_S)\
**Post date:** [February 23, 2024, 8:20pm UTC](https://forum.inductiveautomation.com/t/downsampling-historic-tags-on-average-for-current-month/86291/1 "2024-02-23T20:20:16Z")

</div>

I have historical tags that are secondly. I'd like to slice down to the current month (from midnight on the first of the month to `now()` and resample the tag (like `pandas.DataFrame.resample()` in Python3) to a 1min rolling mean and a 15min rolling mean. Following that, I'll need to run some calculations on each set, but will need the sets themselves for other things.

What's the best way to go about this? I know exactly how to do this in Python3/pandas, but getting it done within the ignition ecosystem isn't clear to me. I've been up and down this forum and Inductive University and can't seem to find an answer that makes sense for my uses. Any assistance is much appreciated.

---

<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:** [February 23, 2024, 8:57pm UTC](https://forum.inductiveautomation.com/t/downsampling-historic-tags-on-average-for-current-month/86291/2 "2024-02-23T20:57:50Z")

</div>

Do you want to do this operation once, or automatically at some particular frequency?

---

<div class="post-metadata">

**Author:** ![D\_S](https://avatars.discourse-cdn.com/v4/letter/d/2bfe46/32.png) [@D\_S](https://forum.inductiveautomation.com/u/D_S)\
**Post date:** [February 23, 2024, 8:59pm UTC](https://forum.inductiveautomation.com/t/downsampling-historic-tags-on-average-for-current-month/86291/3 "2024-02-23T20:59:15Z")

</div>

Periodically, say, hourly?

---

<div class="post-metadata">

**Author:** ![D\_S](https://avatars.discourse-cdn.com/v4/letter/d/2bfe46/32.png) [@D\_S](https://forum.inductiveautomation.com/u/D_S)\
**Post date:** [March 4, 2024, 4:23pm UTC](https://forum.inductiveautomation.com/t/downsampling-historic-tags-on-average-for-current-month/86291/4 "2024-03-04T16:23:57Z")

</div>

Bumping to see if you have any advice for this. Thanks!

---

<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:** [March 4, 2024, 4:29pm UTC](https://forum.inductiveautomation.com/t/downsampling-historic-tags-on-average-for-current-month/86291/5 "2024-03-04T16:29:52Z")

</div>

Your best bet is probably going to be to encapsulate the logic to perform the tag history aggregation you want, via [`system.tag.queryTagHistory`](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-queryTagHistory).  
I would recommend leaving the start and end date as inputs to your script, but encapsulating most/all of the other history query parameters in the script.

Then, you have a few options.  
I would personally recommend a [gateway scheduled script](https://www.docs.inductiveautomation.com/docs/8.1/platform/scripting/scripting-in-ignition/gateway-event-scripts#gateway-scheduled-scripts) that writes out to particular memory tag(s) that holds the aggregated dataset(s).

Or, if you want to have the call to the script "closer" to the final tag, you could potentially use the [`runScript`](https://www.docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/advanced/runScript) expression function in an expression tag to run your project library script and return the results directly.

---

<div class="post-metadata">

**Author:** ![D\_S](https://avatars.discourse-cdn.com/v4/letter/d/2bfe46/32.png) [@D\_S](https://forum.inductiveautomation.com/u/D_S)\
**Post date:** [March 6, 2024, 6:52pm UTC](https://forum.inductiveautomation.com/t/downsampling-historic-tags-on-average-for-current-month/86291/6 "2024-03-06T18:52:14Z")

</div>

Thanks very much. I have few scripts running now on Scheduled that write dataset Memory tags, these tags feed some plots I needed. That's the first part. Now need to work on slicing data to current month AND need separate slices for a certain time period on weekdays.
