# How do I write accumulated values to a label by setting the time interval? for example: daily, weekly, etc

**URL:** <https://forum.inductiveautomation.com/t/how-do-i-write-accumulated-values-to-a-label-by-setting-the-time-interval-for-example-daily-weekly-etc/28592>\
**Category:** Ignition\
**Created:** [September 26, 2019, 3:48pm UTC](https://forum.inductiveautomation.com/t/how-do-i-write-accumulated-values-to-a-label-by-setting-the-time-interval-for-example-daily-weekly-etc/28592 "2019-09-26T15:48:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![felipe2010silva](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@felipe2010silva](https://forum.inductiveautomation.com/u/felipe2010silva)\
**Post date:** [September 26, 2019, 3:48pm UTC](https://forum.inductiveautomation.com/t/how-do-i-write-accumulated-values-to-a-label-by-setting-the-time-interval-for-example-daily-weekly-etc/28592/1 "2019-09-26T15:48:41Z")

</div>

Good Morning. I’m new to ignition and I have a question that I think is easy.  
I added a Label and in its properties I put the expression:

{Machines\_DM/Decorator0201/Count\_MandrelTrip6\_PLC}

which is an OPC-type historian tag that collects trip data from a machine chuck. In real time it gives me the number 5.  
but my goal is to save this data and whenever I select a **start time** and **end time** interval (daily, weekly, monthly, yearly) from Popup Calendar and when I click uptade button the label will provide me the accumulated value depending on the range I set.  
Please, look at the image below

 ![IMAGE5](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6502a542e2499e79c746c4489fc76ad1043a01a1.png)Preformatted text

---

<div class="post-metadata">

**Author:** ![accyroy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/accyroy/32/3386_2.png) [@accyroy](https://forum.inductiveautomation.com/u/accyroy)\
**Post date:** [September 26, 2019, 11:38pm UTC](https://forum.inductiveautomation.com/t/how-do-i-write-accumulated-values-to-a-label-by-setting-the-time-interval-for-example-daily-weekly-etc/28592/2 "2019-09-26T23:38:49Z")

</div>

Hi Felipe, I believe there is a script on the button marked Update which should do the work that you need to display the values of each trip in your selected time frame. There should be a similar screen in your project for Bodymaker Short Cans which may provide more information.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [September 27, 2019, 12:10am UTC](https://forum.inductiveautomation.com/t/how-do-i-write-accumulated-values-to-a-label-by-setting-the-time-interval-for-example-daily-weekly-etc/28592/3 "2019-09-27T00:10:59Z")

</div>

You can just use the sum expression to sum the column of the charts dataset that contains the values you want.

[https://docs.inductiveautomation.com/display/DOC80/sum](https://docs.inductiveautomation.com/display/DOC80/sum)

---

<div class="post-metadata">

**Author:** ![felipe2010silva](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@felipe2010silva](https://forum.inductiveautomation.com/u/felipe2010silva)\
**Post date:** [September 27, 2019, 12:14pm UTC](https://forum.inductiveautomation.com/t/how-do-i-write-accumulated-values-to-a-label-by-setting-the-time-interval-for-example-daily-weekly-etc/28592/4 "2019-09-27T12:14:53Z")

</div>

Good morning accyroy. It really has a screen with the number of short can of bodymakers. but the labels are fed by a table from the MES Analysis controller component. The script associated with the UPDATE button is this:

```auto
startTime=event.source.startDate
endTime=event.source.endDate

tags = ["machines_dm/bm0101/speed", "machines_dm/bm0102/speed", "machines_dm/bm0103/speed", "machines_dm/bm0104/speed", "machines_dm/bm0105/speed", "machines_dm/bm0106/speed", "machines_dm/bm0107/speed","machines_dm/cupper0101/speed"]
ds = system.tag.queryTagHistory(paths=tags, startDate=startTime, endDate=endTime, returnSize=1, aggregationMode="SimpleAverage")

event.source.parent.averageSpeeds = ds
#event.source.parent.getComponent('AC_Controller').startDate = startTime
#event.source.parent.getComponent('AC_Controller').endDate = endTime
#
#event.source.parent.getComponent('Button 4').startTime = startTime
#event.source.parent.getComponent('Button 4').endTime = endTime

```

The problem is, I don’t want to feed direct labels from an MES Analysis Controller table, because I don’t know how to create this table, but I want to feed labels direct from an OPC tag.  
Here’s how the shortcan screen you suggested I do:

 ![image6](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/045a6d6f0a0c44588f994aa904c22ed627ef6417.png)

---

<div class="post-metadata">

**Author:** ![accyroy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/accyroy/32/3386_2.png) [@accyroy](https://forum.inductiveautomation.com/u/accyroy)\
**Post date:** [September 27, 2019, 5:48pm UTC](https://forum.inductiveautomation.com/t/how-do-i-write-accumulated-values-to-a-label-by-setting-the-time-interval-for-example-daily-weekly-etc/28592/5 "2019-09-27T17:48:34Z")

</div>

OK, it looks like the BM avg speeds are being written to a possibly hidden table called averageSpeeds.  
You can use the same method for your mandrel trips. But change the queryTagHistory aggregation mode to return the sum instead of average.  
Create a table and call it mandreltrips then run this script on the button, you should see the results you require, then reference the individual data points the same way the BM AVG speed labels do it.

```auto
startTime=event.source.startDate
endTime=event.source.endDate
tags = ["machines_dm/decorator0201/count_mandreltrip1_plc", "machines_dm/decorator0201/count_mandreltrip2_plc", "machines_dm/decorator0201/count_mandreltrip3_plc", "machines_dm/decorator0201/count_mandreltrip4_plc", "machines_dm/decorator0201/count_mandreltrip5_plc", "machines_dm/decorator0201/count_mandreltrip6_plc", "machines_dm/decorator0201/count_mandreltrip7_plc","machines_dm/decorator0201/count_mandreltrip8_plc"]
ds = system.tag.queryTagHistory(paths=tags, startDate=startTime, endDate=endTime, returnSize=1, aggregationMode="Sum")
event.source.parent.mandreltrips = ds

```

---

<div class="post-metadata">

**Author:** ![felipe2010silva](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@felipe2010silva](https://forum.inductiveautomation.com/u/felipe2010silva)\
**Post date:** [September 27, 2019, 8:06pm UTC](https://forum.inductiveautomation.com/t/how-do-i-write-accumulated-values-to-a-label-by-setting-the-time-interval-for-example-daily-weekly-etc/28592/6 "2019-09-27T20:06:28Z")

</div>

worked perfectly!!! Thanks a lot for the help
