# CountIf a tag is greater than zero between a date range

**URL:** <https://forum.inductiveautomation.com/t/countif-a-tag-is-greater-than-zero-between-a-date-range/69969>\
**Category:** General Discussion\
**Tags:** scripting\
**Created:** [February 16, 2023, 8:29pm UTC](https://forum.inductiveautomation.com/t/countif-a-tag-is-greater-than-zero-between-a-date-range/69969 "2023-02-16T20:29:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Blaschuk](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Ben\_Blaschuk](https://forum.inductiveautomation.com/u/Ben_Blaschuk)\
**Post date:** [February 16, 2023, 8:29pm UTC](https://forum.inductiveautomation.com/t/countif-a-tag-is-greater-than-zero-between-a-date-range/69969/1 "2023-02-16T20:29:52Z")

</div>

All,

I have a data tag that is always on. I want to count the number of seconds that it is grater than zero over an established time range using custom properties. i have tried both system.tag.queryTag History and Calculation. These give me the number of seconds that it that is active. Its active as long as the process is running. any other thoughts?

below is what i have tried with all of the different aggregation modes available.

system.tag.queryTagCalculations(paths,calculations=["DurationOn"],startDate=dayStartTime6A,endDate=nightStartTime6P)

system.tag.queryTagHistory(paths,startDate=nightStartTime6P,endDate=nightStopTime6P,returnSize=1,aggregationMode="DurationOn")

---

<div class="post-metadata">

**Author:** ![Ben\_Blaschuk](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Ben\_Blaschuk](https://forum.inductiveautomation.com/u/Ben_Blaschuk)\
**Post date:** [February 17, 2023, 3:53pm UTC](https://forum.inductiveautomation.com/t/countif-a-tag-is-greater-than-zero-between-a-date-range/69969/2 "2023-02-17T15:53:17Z")

</div>

looked at it again and i did use the above correctly. Just looked weird. 🙂
