# Help on creating custom Historian Aggregates

**URL:** <https://forum.inductiveautomation.com/t/help-on-creating-custom-historian-aggregates/60577>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [June 9, 2022, 7:52pm UTC](https://forum.inductiveautomation.com/t/help-on-creating-custom-historian-aggregates/60577 "2022-06-09T19:52:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torsten\_Giesbrecht](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@Torsten\_Giesbrecht](https://forum.inductiveautomation.com/u/Torsten_Giesbrecht)\
**Post date:** [June 9, 2022, 7:52pm UTC](https://forum.inductiveautomation.com/t/help-on-creating-custom-historian-aggregates/60577/1 "2022-06-09T19:52:31Z")

</div>

I’m having some issues creating custom historian aggregates. What I want to do is get the average for a days worth of historical data, but omit any 0 values from the average. I’m new to Ignition and scripting, and am having trouble understanding the example in the manual:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/4/74d23eb236f9661c3739ae5eeb45593452045c8e.png)

It would help if I knew what to expect from the example given. When I run the example code with interpolation off I get:

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

Shouldn’t I be getting a single value of cnt back from the function that represents the number of good quality rows? Instead I get a table of data with 0s in it for every time stamp.

---

<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:** [June 9, 2022, 8:33pm UTC](https://forum.inductiveautomation.com/t/help-on-creating-custom-historian-aggregates/60577/2 "2022-06-09T20:33:43Z")

</div>

Is your historian module actively licensed? Are there any errors in the gateway logs?

---

<div class="post-metadata">

**Author:** ![Torsten\_Giesbrecht](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@Torsten\_Giesbrecht](https://forum.inductiveautomation.com/u/Torsten_Giesbrecht)\
**Post date:** [June 9, 2022, 9:07pm UTC](https://forum.inductiveautomation.com/t/help-on-creating-custom-historian-aggregates/60577/3 "2022-06-09T21:07:20Z")

</div>

Historian is licensed. When I execute the script it shows no errors, but the gateway logs do show an error:

com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File “”, line 2, in pyaggimpl NameError: global name ‘shared’ is not defined

![Capture2](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/b/bb415c7f7cf0cafa77e42655c21413ebb9a0fc7f.png)

---

<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:** [June 9, 2022, 9:10pm UTC](https://forum.inductiveautomation.com/t/help-on-creating-custom-historian-aggregates/60577/4 "2022-06-09T21:10:01Z")

</div>

Where do you have your aggregate script defined? Is it in a lib called literally `shared` or something similar? Is it set as your gateway scripting project( I don’t know if that’s documented but I think might be required).

---

<div class="post-metadata">

**Author:** ![Torsten\_Giesbrecht](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@Torsten\_Giesbrecht](https://forum.inductiveautomation.com/u/Torsten_Giesbrecht)\
**Post date:** [June 10, 2022, 12:04pm UTC](https://forum.inductiveautomation.com/t/help-on-creating-custom-historian-aggregates/60577/5 "2022-06-10T12:04:14Z")

</div>

I believe I have it in the right place.

 ![Capture3](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/2/f2f5a0581edb6cb6eedd377657fef643a9aefbe8.png)

---

<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:** [June 10, 2022, 2:47pm UTC](https://forum.inductiveautomation.com/t/help-on-creating-custom-historian-aggregates/60577/6 "2022-06-10T14:47:05Z")

</div>

Is it set as your gateway scripting project?

---

<div class="post-metadata">

**Author:** ![Torsten\_Giesbrecht](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@Torsten\_Giesbrecht](https://forum.inductiveautomation.com/u/Torsten_Giesbrecht)\
**Post date:** [June 13, 2022, 2:24pm UTC](https://forum.inductiveautomation.com/t/help-on-creating-custom-historian-aggregates/60577/7 "2022-06-13T14:24:16Z")

</div>

This was the issue. I misunderstood the gateway scripting in the instructions. Thanks for pointing it out.
