# Getting tag data from tag History

**URL:** <https://forum.inductiveautomation.com/t/getting-tag-data-from-tag-history/81896>\
**Category:** Ignition\
**Tags:** ignition80, database, vision\
**Created:** [November 14, 2023, 8:48pm UTC](https://forum.inductiveautomation.com/t/getting-tag-data-from-tag-history/81896 "2023-11-14T20:48:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Austin\_Allen](https://avatars.discourse-cdn.com/v4/letter/a/f0a364/32.png) [@Austin\_Allen](https://forum.inductiveautomation.com/u/Austin_Allen)\
**Post date:** [November 14, 2023, 8:48pm UTC](https://forum.inductiveautomation.com/t/getting-tag-data-from-tag-history/81896/1 "2023-11-14T20:48:55Z")

</div>

Hello,

I have a tag " Pump\_On\_IND" that is == 1 whenever the pump is running.  
I am trying to implement this formula into my report designer:

Total Gallons Flowed = "Pump\_On\_IND" \* 287.5

In these reports, each row is a unique batch. I would like for this to calculate the gallons flowed for each batch, and put it in a column in my report designer.

I achieved using the DurationOn aggregate, but when I used it in a column, it reported the entire start date to end date total (same number in every row for that column). It did not separate it by batch.

Could anyone point me in the right direction here?

---

<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:** [November 14, 2023, 9:21pm UTC](https://forum.inductiveautomation.com/t/getting-tag-data-from-tag-history/81896/2 "2023-11-14T21:21:59Z")

</div>

Unfortunately, this is not something the tag historian does well. You will probably want to query for the "as stored" raw on-off events, then construct your dataset in a script.

---

<div class="post-metadata">

**Author:** ![Austin\_Allen](https://avatars.discourse-cdn.com/v4/letter/a/f0a364/32.png) [@Austin\_Allen](https://forum.inductiveautomation.com/u/Austin_Allen)\
**Post date:** [November 14, 2023, 9:25pm UTC](https://forum.inductiveautomation.com/t/getting-tag-data-from-tag-history/81896/3 "2023-11-14T21:25:24Z")

</div>

Can you tell me where I can read about "query for 'as stored' raw on-off events"? I'm not sure where to find that

---

<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:** [November 14, 2023, 9:30pm UTC](https://forum.inductiveautomation.com/t/getting-tag-data-from-tag-history/81896/4 "2023-11-14T21:30:01Z")

</div>

It's triggered when you specify `returnSize=-1` in your scripted tag history query. Then you'll get a row for every change in the pump status. Your script will then have to loop through those noting the start and stop timestamps for a new dataset.
