# Tag history binding periodic aggregation

**URL:** <https://forum.inductiveautomation.com/t/tag-history-binding-periodic-aggregation/69417>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [February 3, 2023, 4:58pm UTC](https://forum.inductiveautomation.com/t/tag-history-binding-periodic-aggregation/69417 "2023-02-03T16:58:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bfreeman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfreeman/32/87436_2.png) [@bfreeman](https://forum.inductiveautomation.com/u/bfreeman)\
**Post date:** [February 3, 2023, 4:58pm UTC](https://forum.inductiveautomation.com/t/tag-history-binding-periodic-aggregation/69417/1 "2023-02-03T16:58:42Z")

</div>

Hi,

I am trying to understand how the periodic aggregation for a tag history binding works.

More specifically the behavior of the time units in the dropdown:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/c/3c61aaeda2bce7c29fde3569cb02c198ddc22737.png)

**DAY** seems correspond to sliding 24h (based on selected time) and not from 12am to 12am, right?  
Same question goes for **WEEK** (sliding 7 days?) and **MONTH** (sliding XX days?).

I looked at the [Tag History Bindings in Perspective](https://docs.inductiveautomation.com/display/DOC81/Tag+History+Bindings+in+Perspective) documentation but there is no precision on this matter.

I'd be grateful if someone could shed some light on this subject.

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:** [February 3, 2023, 5:43pm UTC](https://forum.inductiveautomation.com/t/tag-history-binding-periodic-aggregation/69417/2 "2023-02-03T17:43:57Z")

</div>

For a historical binding, if you set the query mode to periodic, the _end_ date of the query will be adjusted to give you an even N intervals of size `period` from `start` to `end`. So if you want e.g. midnight -\> midnight intervals, you just make sure that your start date is normalized to midnight before passing.

---

<div class="post-metadata">

**Author:** ![bfreeman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfreeman/32/87436_2.png) [@bfreeman](https://forum.inductiveautomation.com/u/bfreeman)\
**Post date:** [February 3, 2023, 6:10pm UTC](https://forum.inductiveautomation.com/t/tag-history-binding-periodic-aggregation/69417/3 "2023-02-03T18:10:00Z")

</div>

Ok, thanks, this confirms my observations.

To be clear, could you therefore please confirm the following behavior:

- 1 **DAY** = 24 **HOUR** s
- 1 **WEEK** = 7 **DAY** s = 168 **HOUR** s
- 1 **MONTH** = 28? 30? 31? **DAY** s

IMHO I don't see the point of these units if this is the case. It is prone to confusion.

Also I don't quite understand the adjustment you mention. Want happens if the diff between `end` and `start` is not a multiple of the `period`? Let's say the diff is 40 hours and the `period` set is 24 **HOUR** s. Is the `period` resized to 20 hours for even intervals or else?

---

<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 3, 2023, 6:43pm UTC](https://forum.inductiveautomation.com/t/tag-history-binding-periodic-aggregation/69417/4 "2023-02-03T18:43:25Z")

</div>

> [@bfreeman](#):
>
> IMHO I don't see the point of these units if this is the case.

I mean, would you rather set a period of 604800 seconds, or 1 week? It's all ultimately _milliseconds_ under the hood. The different units are just a convenience.

> [@bfreeman](#):
>
> Want happens if the diff between `end` and `start` is not a multiple of the `period`? Let's say the diff is 40 hours and the `period` set is 24 **HOUR** s. Is the `period` resized to 20 hours for even intervals or else?

From what I see in the code, it looks like in this particular case the end date would be adjusted to 48 hours (i.e. start: Jan1@midnight, end: Jan3@midnight) but the 'return size' will be _2_, so you'll get two output rows: Jan1@midnight, and Jan2@midnight.

In other words: The window is always _enlarged_ to fit the interval specified.

---

<div class="post-metadata">

**Author:** ![bfreeman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfreeman/32/87436_2.png) [@bfreeman](https://forum.inductiveautomation.com/u/bfreeman)\
**Post date:** [February 3, 2023, 7:34pm UTC](https://forum.inductiveautomation.com/t/tag-history-binding-periodic-aggregation/69417/5 "2023-02-03T19:34:00Z")

</div>

> [@paul-griffith](#):
>
> > [@bfreeman](#):
> >
> > IMHO I don't see the point of these units if this is the case.
> 
> I mean, would you rather set a period of 604800 seconds, or 1 week? It's all ultimately _milliseconds_ under the hood. The different units are just a convenience.

Haha, sure 😅 My point was more on the semantic.

I agree a week is 604800 seconds 🙃 but what about **month** (and **year** to a greater extent)?

> [@paul-griffith](#):
>
> From what I see in the code, it looks like in this particular case the end date would be adjusted to 48 hours (i.e. start: Jan1@midnight, end: Jan3@midnight) but the 'return size' will be _2_, so you'll get two output rows: Jan1@midnight, and Jan2@midnight.

Understood! Thanks for looking into the code!

I think all this deserves to be documented.

---

<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 3, 2023, 8:23pm UTC](https://forum.inductiveautomation.com/t/tag-history-binding-periodic-aggregation/69417/6 "2023-02-03T20:23:32Z")

</div>

Yeah, it's admittedly imperfect. For what it's worth, a month is hardcoded to 30 days, and a year is hardcoded to 365 days. True date math would definitely be nice to have in these functions, but will probably have to wait for a larger revamp of the historian down the road.

---

<div class="post-metadata">

**Author:** ![bfreeman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfreeman/32/87436_2.png) [@bfreeman](https://forum.inductiveautomation.com/u/bfreeman)\
**Post date:** [February 3, 2023, 9:00pm UTC](https://forum.inductiveautomation.com/t/tag-history-binding-periodic-aggregation/69417/7 "2023-02-03T21:00:51Z")

</div>

Thanks for clarifying month and year.

For me, the main point is properly understanding the implemented mechanics to avoid surprises.
