# Calculate Duration On of multiple tags

**URL:** <https://forum.inductiveautomation.com/t/calculate-duration-on-of-multiple-tags/87882>\
**Category:** Ignition\
**Tags:** vision, ignition81, scripting\
**Created:** [March 26, 2024, 9:39am UTC](https://forum.inductiveautomation.com/t/calculate-duration-on-of-multiple-tags/87882 "2024-03-26T09:39:40Z")\
**Posts on this page:** 1\
**Showing post:** 7

<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 26, 2024, 11:36am UTC](https://forum.inductiveautomation.com/t/calculate-duration-on-of-multiple-tags/87882/7 "2024-03-26T11:36:44Z")

</div>

Once you have that set up, the queries will use the `lead()` or `lag()` functions to get adjacent timestamps for deltas. In your case, you will need to use the `PARTITION BY` clause in your window functions so that the calculations are per-tagpath.

(I wouldn't store tagpaths directly in this table--make a joinable table that holds the full tag path and use that table's primary key in the event table.)

See this topic for an example:

> [@User login,logout and Session Info](https://forum.inductiveautomation.com/t/user-login-logout-and-session-info/41889/4):
>
> Try something like this: Select \*, "NEXT\_TSTAMP" - "EVENT\_TIMESTAMP" As "DURATION" From ( Select \*, lead("ACTION") OVER (Partition By "ACTOR" Order By "EVENT\_TIMESTAMP") As "NEXT\_TSTAMP" From audit\_events Where ....... ) subq Where "ACTION"='login' Order By EVENT\_TIMESTAMP The last login, if not yet logged out, will have nulls for NEXT\_TSTAMP and DURATION.

(You would partition by `event_tag_id` instead of `ACTOR`.)

---

_[View the full topic](https://forum.inductiveautomation.com/t/calculate-duration-on-of-multiple-tags/87882)._
