# Basic Average Woes

**URL:** <https://forum.inductiveautomation.com/t/basic-average-woes/106651>\
**Category:** Ignition\
**Tags:** reporting\
**Created:** [May 23, 2025, 8:11pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651 "2025-05-23T20:11:52Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![downerczx](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/downerczx/32/11649_2.png) [@downerczx](https://forum.inductiveautomation.com/u/downerczx)\
**Post date:** [May 23, 2025, 8:11pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/1 "2025-05-23T20:11:52Z")

</div>

I'm doing a report, and taking basic average for every hour (interval) for 24 hours. From Midnight to Midnight (all the way to seconds, 00:00:00) I keep getting slightly different numbers... this shouldn't be.... does Basic Average have some fuzzy precision or something that is keeping it from giving me the same numbers?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 23, 2025, 10:19pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/2 "2025-05-23T22:19:56Z")

</div>

1. Where's the data coming from?
2. Are there actual records at 00:00:00?
3. What's the query?
4. "_I keep getting slightly different numbers._" On the same query or on similar queries?

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 23, 2025, 11:40pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/3 "2025-05-23T23:40:00Z")

</div>

And most importantly, _what's the script you're using?_ we can't even begin to help without knowing what you're doing 🙂

---

<div class="post-metadata">

**Author:** ![downerczx](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/downerczx/32/11649_2.png) [@downerczx](https://forum.inductiveautomation.com/u/downerczx)\
**Post date:** [June 4, 2025, 10:14pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/4 "2025-06-04T22:14:21Z")

</div>

Hi all, thank you and sorry for the late response... I'm not even using a script, I'm just using some tags as a data source with 'Basic Average' as the Aggregation Mode. The sample size is interval with 24 hours. The numbers come back differently each time I run it even though the start and stop dates are the same.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 5, 2025, 12:04am UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/5 "2025-06-05T00:04:04Z")

</div>

Oh, I assumed cause of this:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/9/d91fee0b8740d3771f7774dcfde22ae4a532e42a.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 5, 2025, 10:33pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/6 "2025-06-05T22:33:31Z")

</div>

You'll need to supply _a lot_ more information before anyone can figure out what you're doing and what could possibly be wrong.

"Basic Average" is mentioned in the documentation in the context of [Tag History Bindings in Vision | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/ignition-modules/vision/binding-types-in-vision/tag-history-bindings-in-vision#aggregation-mode) but you haven't mentioned tag history in your posts. (And you haven't answered the questions asked in post #2.) If you are using this then you also need to study how the tag historian works. There's a link in the article.

---

<div class="post-metadata">

**Author:** ![downerczx](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/downerczx/32/11649_2.png) [@downerczx](https://forum.inductiveautomation.com/u/downerczx)\
**Post date:** [June 6, 2025, 2:45pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/7 "2025-06-06T14:45:55Z")

</div>

Fair! To all have have pointed out my lack of detail, I apologize, and thank you for answering my questions. Here you can see I am trying to make a rough 'midnight' to 'midnight' with StartDate and EndDate params. That 2nd column, lbsperhour\_mod always comes back with a different value.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/8/68cc42d68297024583241b5343d3bab37b70c982.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/f/4f7810e4413649c5ea836f71604a97739f7ef600.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/0/c092620b136db05f0c50da0a775dc1d79e9c0e8d.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/a/caa26293ffce15d423ad35d889fdf90e163aaccb.png)

Observe this report, run twice within seconds, with a different result.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/1/11a56934a436ee247c5ac71f655decec963ef4b0.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/0/c0ddf6862ae917187add34737303f40304e66d07.png)

Strangely, it seems like only the bottom row is changing.

---

<div class="post-metadata">

**Author:** ![downerczx](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/downerczx/32/11649_2.png) [@downerczx](https://forum.inductiveautomation.com/u/downerczx)\
**Post date:** [June 6, 2025, 2:47pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/8 "2025-06-06T14:47:00Z")

</div>

changed to 'reporting' tag!

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [June 6, 2025, 2:52pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/9 "2025-06-06T14:52:04Z")

</div>

So you want midnight to midnight for the current day or the previous day?

Why not use the [midnight | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/date-and-time/midnight) expression function to generate the proper timestamp rather than the complex date arithmetic?

---

<div class="post-metadata">

**Author:** ![downerczx](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/downerczx/32/11649_2.png) [@downerczx](https://forum.inductiveautomation.com/u/downerczx)\
**Post date:** [June 6, 2025, 3:00pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/10 "2025-06-06T15:00:06Z")

</div>

I take it back, I'm trying to do last 24 hours to present, not midnight to midnight.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 6, 2025, 3:33pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/11 "2025-06-06T15:33:51Z")

</div>

> [@downerczx](#):
>
> last 24 hours to present

Wouldn't that just be:

```python
//StartDate
setTime(addHours(now(),-23),getHour24(addHours(now(),-23)),0,0)

//EndDate set to next flat hour
setTime(now(), getHour24(addHours(now(),1)),0,0)

```

Or

```python
//StartDate
setTime(addHours(now(),-24),getHour24(addHours(now(),-24)),0,0)

//EndDate set to flat hour
setTime(now(), getHour24(now()),0,0)

```

Also, on your Tag History query, if you expand the Advanced section, do you have `Prevent Interpolation` Checked?

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [June 6, 2025, 4:40pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/12 "2025-06-06T16:40:30Z")

</div>

Then every-time you run it, it will be different won't it? If the data is constantly changing, so I would assume that the average would also be changing as your window is sliding.

Like @lrose said. Make sure prevent interpolation is ~~un-checked~~ checked.

---

<div class="post-metadata">

**Author:** ![downerczx](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/downerczx/32/11649_2.png) [@downerczx](https://forum.inductiveautomation.com/u/downerczx)\
**Post date:** [June 6, 2025, 4:44pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/13 "2025-06-06T16:44:06Z")

</div>

So the weird thing is the data is constantly changing for the last hour on that list. So, it's a previous hour (which should be properly defined as an hour). The arithmetic whittles off all of the seconds and minutes so that it should be an unchanging hour window.

---

<div class="post-metadata">

**Author:** ![downerczx](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/downerczx/32/11649_2.png) [@downerczx](https://forum.inductiveautomation.com/u/downerczx)\
**Post date:** [June 6, 2025, 4:45pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/14 "2025-06-06T16:45:23Z")

</div>

Interpolation is unchecked. I'll try those versions... but it seems like mine are working from the StartDate and EndDate that are printed on the report.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 6, 2025, 4:49pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/15 "2025-06-06T16:49:34Z")

</div>

Prevent Interpolation should be checked. That way the system isn't injecting values that don't exist.

---

<div class="post-metadata">

**Author:** ![downerczx](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/downerczx/32/11649_2.png) [@downerczx](https://forum.inductiveautomation.com/u/downerczx)\
**Post date:** [June 6, 2025, 4:56pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/16 "2025-06-06T16:56:14Z")

</div>

> [@lrose](#):
>
> `setTime(now(), getHour24(addHours(now(),1)),0,0)`

Awesome, thank you! So it seems my arithmetic expression wasn't up to the task but the ones you provided are yielding unchanging results.

I extended out my time startdate/enddate printouts to include seconds, and my expression still shows correctly:

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/8/28764a8ed6bd2244a6ca377cee41c2bb9a936e68.png)

I get the almost same output with your expressions:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/5/552b92e420e330465fbae245b109cf96dc6d11f4.png)

I'm not sure why, but the version you had works better. It also includes the current hour kind of in the end date, but it doesn't show that row yet at the top of the report (good because the hour isn't complete).

Weird, but solved! Thank you. It would be nice to know why that happens.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 6, 2025, 6:28pm UTC](https://forum.inductiveautomation.com/t/basic-average-woes/106651/17 "2025-06-06T18:28:45Z")

</div>

That your expressions were working at all, is a bit suprising to me, as the [documentation](https://www.docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/date-and-time/dateArithmetic) for the `dateArithmetic()` function doesn't list `'min'` as a valid field value. That may just be an error in the manual though.

The only thing I can come up with is that the `dateArithmetic()` function will preserve the millisecond field of the date object it works against, where as the `setTime()` function is documented to **not** preserve the millisecond field. Meaning that it will return a date with the millisecond field set to zero. Because the historian stores data by millisecond this does matter in the context of your query. So, you would include or exclude particular data points depending on the millisecond field.
