# Can you make a Query tag that queries a tag in Tag History? How?

**URL:** <https://forum.inductiveautomation.com/t/can-you-make-a-query-tag-that-queries-a-tag-in-tag-history-how/36967>\
**Category:** Ignition\
**Created:** [July 22, 2020, 7:45pm UTC](https://forum.inductiveautomation.com/t/can-you-make-a-query-tag-that-queries-a-tag-in-tag-history-how/36967 "2020-07-22T19:45:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wking](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wking/32/21823_2.png) [@wking](https://forum.inductiveautomation.com/u/wking)\
**Post date:** [July 22, 2020, 7:45pm UTC](https://forum.inductiveautomation.com/t/can-you-make-a-query-tag-that-queries-a-tag-in-tag-history-how/36967/1 "2020-07-22T19:45:36Z")

</div>

I am using tag history bindings. Through a flex repeater(30 instances) to evaluate Duration On of a bool Expression tag(“Producing”). That is an expression of several OPC tags. That eventually compares against seconds in a shift or day.

Works great. But, consumes a ton of resources. When it polls.

I need to get a query tag that provides me a scalar value of Duration On of this “Producing” tag.

But I don’t know how to query the historian manually. Should it be a query tag or tag change script using [system.tag.queryTagHistory - Ignition User Manual 8.0 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC80/system.tag.queryTagHistory) or what?

```auto
{
  "type": "tag-history",
  "config": {
    "dateRange": {
      "startDate": "{[default]SCADA/Time/shift.Timestamp}",
      "endDate": "now(30000)"
    },
    "calculations": [
      "DurationOn"
    ],
    "tags": "{view.custom.hist}",
    "returnFormat": "Calculations",
    "valueFormat": "DOCUMENT",
    "ignoreBadQuality": false,
    "preventInterpolation": false,
    "avoidScanClassValidation": true
  }
}

```

view.custom.hist 👇

```auto
[
  {
    "aggregate": "DurationOn",
    "alias": "ava",
    "path": "[default]D06/D06/Status/Producing"
  }
]

```

Any guidance on how to wrap this all up in a tag to provide an int of seconds of duration on for [default]D06/D06/Status/Producing. So all the instances can just read a tag. Instead of individually querying

Would be much appreciated.

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [July 22, 2020, 8:21pm UTC](https://forum.inductiveautomation.com/t/can-you-make-a-query-tag-that-queries-a-tag-in-tag-history-how/36967/2 "2020-07-22T20:21:16Z")

</div>

For something similar I’m using [system.tag.queryTagCalculations()](https://docs.inductiveautomation.com/display/DOC80/system.tag.queryTagCalculations). I have to return a count and duration on for multiple tags though, the line I’m using for it is,modified by what I see above:

```auto
pathIn = ["[default]D06/D06/Status/Producing"]
start = system.tag.read('[default]SCADA/Time/shift').timestamp
end = system.date.now()
hist = system.tag.queryTagCalculations(paths=pathIn,calculations=['DurationOn'],startDate=start,endDate=end,ignoreBadQuality=1,includeBoundingValues=0)

```

I’m running this in a gateway timer script so it doesn’t put the load on the UI. Then in my script I’m breaking it up into the individual values and feeding them into memory tags to use on the screen.
