# Sum tag value for 24hr period

**URL:** <https://forum.inductiveautomation.com/t/sum-tag-value-for-24hr-period/92724>\
**Category:** Ignition\
**Created:** [July 3, 2024, 1:23am UTC](https://forum.inductiveautomation.com/t/sum-tag-value-for-24hr-period/92724 "2024-07-03T01:23:44Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![Karl\_Eckermann](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@Karl\_Eckermann](https://forum.inductiveautomation.com/u/Karl_Eckermann)\
**Post date:** [July 26, 2024, 12:37am UTC](https://forum.inductiveautomation.com/t/sum-tag-value-for-24hr-period/92724/21 "2024-07-26T00:37:41Z")

</div>

I have added the following code to a gateway tag change script and works as it should.

```python
dsResults = system.tag.queryTagHistory(
    paths = ['[Weather_Stations]Rainfall'],
	aggregationMode = 'Sum',
    startDate = system.date.midnight(system.date.now()),
    rangeHours = 24,
    returnSize = 1,
	noInterpolation = False)
		
pdsResults = system.dataset.toPyDataSet(dsResults)
system.tag.writeAsync(['[Weather_Stations]RainfallTotal'],[pdsResults[0][1]])

```

I has hoping to run in a UDT but it will do for now.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [July 26, 2024, 12:40am UTC](https://forum.inductiveautomation.com/t/sum-tag-value-for-24hr-period/92724/22 "2024-07-26T00:40:57Z")

</div>

You can run it in a UDT, but your paths will need to change for it to be dynamic.

---

<div class="post-metadata">

**Author:** ![Karl\_Eckermann](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@Karl\_Eckermann](https://forum.inductiveautomation.com/u/Karl_Eckermann)\
**Post date:** [July 26, 2024, 1:19am UTC](https://forum.inductiveautomation.com/t/sum-tag-value-for-24hr-period/92724/23 "2024-07-26T01:19:23Z")

</div>

Its got me beat.

When it runs a gateway script it works fine. But when run the script in tag it just replaces the total with the previous. Does not sum.

I have replaced some tags for testing.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/4/64c50467041f0f8e78bac46b4b4a53291f1499b1.png)

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [July 26, 2024, 4:36am UTC](https://forum.inductiveautomation.com/t/sum-tag-value-for-24hr-period/92724/24 "2024-07-26T04:36:20Z")

</div>

Show your UDT that you're wanting to use. You should have a tag named "Rainfall" or something else for the current value, and a "RainfallTotal" tag of some sort for the total. Your value changed script on the "Rainfall" tag would look like this if you're using those 2 tags (we're cheating by appending "Total" to the "Rainfall" to get the tag path for the total:

```python
dsResults = system.tag.queryTagHistory(
    paths = [tagPath],
	aggregationMode = 'Sum',
    startDate = system.date.midnight(system.date.now()),
    intervalMinutes = 5,
    rangeHours = 24,
    returnSize = 1,
	noInterpolation = False)
		
pdsResults = system.dataset.toPyDataSet(dsResults)
system.tag.writeAsync([tagPath + 'Total'],[pdsResults[0][1]])

```

---

<div class="post-metadata">

**Author:** ![Karl\_Eckermann](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@Karl\_Eckermann](https://forum.inductiveautomation.com/u/Karl_Eckermann)\
**Post date:** [July 26, 2024, 5:12am UTC](https://forum.inductiveautomation.com/t/sum-tag-value-for-24hr-period/92724/25 "2024-07-26T05:12:05Z")

</div>

@michael.flagler

Now I just get random numbers in Rainfall total. They even go down when i get a zero rainfall on the update

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/c/bc6c77286a28cf28c84c35dee25dd2b284f8046d.png)

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [July 26, 2024, 2:09pm UTC](https://forum.inductiveautomation.com/t/sum-tag-value-for-24hr-period/92724/26 "2024-07-26T14:09:50Z")

</div>

Ok, I think I see the possible issue. You're missing the intervalMinutes parameter (I went ahead and edited my post and added it to my example as well). See if that helps.

[Previous page](https://forum.inductiveautomation.com/t/sum-tag-value-for-24hr-period/92724.md?page=1)
