# Multistate duration agregation values

**URL:** <https://forum.inductiveautomation.com/t/multistate-duration-agregation-values/104097>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [March 24, 2025, 2:53pm UTC](https://forum.inductiveautomation.com/t/multistate-duration-agregation-values/104097 "2025-03-24T14:53:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martial\_Wilbert](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Martial\_Wilbert](https://forum.inductiveautomation.com/u/Martial_Wilbert)\
**Post date:** [March 24, 2025, 2:53pm UTC](https://forum.inductiveautomation.com/t/multistate-duration-agregation-values/104097/1 "2025-03-24T14:53:44Z")

</div>

Hi all,

I need advices how to manage a situation. We have bacNET multistate objects to collect. Data Acquisition and display perspective views was alright and customer was satisfied.

Now, customer would like to have data analysis on duration by state. Issue is that the tag historian durationOn is for boolean. Just take an example of a fan with a multistate : 0=off; 1=On Speed1; 2= On Speed2; 3=Maintenance mode. Customer wants to know duration of reach state.  
The tag is currently an OPC tag (Short datatype) but nothing was really done to make this duration computation easy.

I'm thinking on 2 ways to answer customer request:  
1 / Trying to create custom aggregate scripts but I'm wondering if this agregate functions are available on Datasource report module; And I'm not sure how to do it.  
2/ Split the multistate on several boolean tags (Expression). Then, I'm wondering if there is a way to evaluate the expression on past historian data to rebuild the booleans tags on the same period than Multistate tags ?

Thanks in advance for your feedbacks.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 24, 2025, 3:01pm UTC](https://forum.inductiveautomation.com/t/multistate-duration-agregation-values/104097/2 "2025-03-24T15:01:42Z")

</div>

Essentially, you need two analytic features, not available in the Ignition historian, to achieve this:

- `lead() over (partition by tag_id, order by t_stamp)` to obtain the end timestamp of any particular interval, and
- `group by stateValue` to keep each state together for summation or other analysis.

The common solution is to not use the tag historian, but to use a custom DB table to record your state changes. Then you can directly use SQL with the given phrases to extract the information you need.

An alternate solution is to use the historian and retrieve the states "As Stored, Tall format" and then script the equivalent to the SQL. (If you go this route, you may find some expression functions in my Integration Toolkit helpful.)

---

<div class="post-metadata">

**Author:** ![Martial\_Wilbert](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Martial\_Wilbert](https://forum.inductiveautomation.com/u/Martial_Wilbert)\
**Post date:** [March 24, 2025, 3:28pm UTC](https://forum.inductiveautomation.com/t/multistate-duration-agregation-values/104097/3 "2025-03-24T15:28:26Z")

</div>

Phil,  
Are you speaking about this kit ? [Ignition Exchange | Inductive Automation](https://inductiveautomation.com/exchange/2687/overview)

Or ??

Thx.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [March 24, 2025, 3:29pm UTC](https://forum.inductiveautomation.com/t/multistate-duration-agregation-values/104097/4 "2025-03-24T15:29:56Z")

</div>

> [@Automation Professionals' Integration Toolkit Module](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934):
>
> Automation Professionals is pleased to announce the immediately availability of a major upgrade to its free Simulation Aids Integration Toolkit module. The new feature justifying the "major upgrade" language is the implementation of eleven thirty-one new expression functions which use iteration to accomplish complex transforms of datasets and lists, to or from other datasets and lists, applying filtering, ordering, and computed new columns along the way. While there are certain operations that…

---

<div class="post-metadata">

**Author:** ![Martial\_Wilbert](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Martial\_Wilbert](https://forum.inductiveautomation.com/u/Martial_Wilbert)\
**Post date:** [March 25, 2025, 9:54am UTC](https://forum.inductiveautomation.com/t/multistate-duration-agregation-values/104097/5 "2025-03-25T09:54:46Z")

</div>

Hi all,  
Finally and for information. We managed with TagHistorian query with an interval of X minutes and the closest value aggregation mode.  
Then we added a subgroup on a table grouped by statevalue. Duration = count \* X interval minutes.

This is working pretty well specially cause on our project the multistate value is not changing so often on period.

Thanks for your feedbacks that allowing me to drive to the correct direction.
