# Find the total sum of a variable starting from a specific time in the past and up until the newest data point

**URL:** <https://forums.losant.com/t/find-the-total-sum-of-a-variable-starting-from-a-specific-time-in-the-past-and-up-until-the-newest-data-point/5039>\
**Category:** Help\
**Tags:** workflow\
**Created:** [April 27, 2023, 3:54pm UTC](https://forums.losant.com/t/find-the-total-sum-of-a-variable-starting-from-a-specific-time-in-the-past-and-up-until-the-newest-data-point/5039 "2023-04-27T15:54:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikolay\_Stepin](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@Nikolay\_Stepin](https://forums.losant.com/u/Nikolay_Stepin)\
**Post date:** [April 27, 2023, 3:54pm UTC](https://forums.losant.com/t/find-the-total-sum-of-a-variable-starting-from-a-specific-time-in-the-past-and-up-until-the-newest-data-point/5039/1 "2023-04-27T15:54:42Z")

</div>

Hi,

I’m trying to figure out a way to find the total sum of a variable and record it in the device data - for example, in my case, say, there is a device which records alarms and with the Data: Gauge Query block it’s easy to keep track of the last hour or 24 hours or any of the (pre)defined time ranges.

I, however, would like to be able to display the total amount of alarms since the device started sending data; given, I have an attribute which keeps track of how many times the event happened per each message. Is there an easy way to set-up a counter with an initial default value that I could calculate myself?

Maybe using the sum aggregation in some specific way? I’ve tried defining a custom time, but I need the time window to increase incrementally as we move away from the date that the device started sending data and I don’t think that’ll happen automatically. Maybe I can pass in a variable that has the right time calculated each workflow call? That’s probably computationally intensive and inefficient.

The other thing it seems that I can do is simply display the total value separately on the dashboard from the other counts and set the time range for that to be greater than ‘x’ of time with the sum aggregation. This would allow me to proceed without altering the workflows that I have, but would it sum a variable past 180 days?

What would be a reasonable way forward or what would you suggest I do?

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![Sebastian\_Turner](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/sebastian_turner/32/4024_2.png) [@Sebastian\_Turner](https://forums.losant.com/u/Sebastian_Turner)\
**Post date:** [April 27, 2023, 5:27pm UTC](https://forums.losant.com/t/find-the-total-sum-of-a-variable-starting-from-a-specific-time-in-the-past-and-up-until-the-newest-data-point/5039/2 "2023-04-27T17:27:02Z")

</div>

Hi @Nikolay_Stepin and welcome to the Losant forums!

As you suggested, you can use the [`sum` aggregation method](https://docs.losant.com/references/aggregations/#sum) in the [Gauge](https://docs.losant.com/dashboards/blocks/gauge/) dashboard block to display the sum of up to 180 days of historical data for a single device attribute across one or more devices.

If you want to display a longer duration, or if you want to run other calculations, I suggest using [workflow storage](https://docs.losant.com/workflows/overview/#workflow-storage) to maintain an iterative value that can be stored as a new device attribute. I created an example of this a few months ago for somebody with a similar use-case. You’ll want to tweak this to fit your specific needs, but hopefully will get you on the right track if you pursue this option:

> [@Display Total per Day on Dashboard](https://forums.losant.com/t/display-total-per-day-on-dashboard/4923/3):
>
> I’ve attached a workflow file that will hopefully help get you started. You’ll definitely want to tweak it to fit for your use: [set-daily-count-develop.flow](https://forums.losant.com/uploads/short-url/3Gnu2K7JiBVJnDHf8ELw23qyIaX.flow) (4.2 KB) Here’s an explanation of the nodes used: [Device: State Trigger](https://docs.losant.com/workflows/triggers/device/) - Activates any time the selected device sends a device state report containing any attribute other than the newCount attribute that we’ll be defining downstream. For this example, let’s say the “total cycles since boot” attrib…

Let us know if one of these options will work for you, and once again, thanks for joining us on our forums!

---

<div class="post-metadata">

**Author:** ![Nikolay\_Stepin](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@Nikolay\_Stepin](https://forums.losant.com/u/Nikolay_Stepin)\
**Post date:** [April 27, 2023, 5:36pm UTC](https://forums.losant.com/t/find-the-total-sum-of-a-variable-starting-from-a-specific-time-in-the-past-and-up-until-the-newest-data-point/5039/3 "2023-04-27T17:36:33Z")

</div>

@Sebastian_Turner,

Thank you for your reply! I did see that post, but I was wondering if there was a simpler way to do it; I’ll go ahead and try to tweak that workflow to my needs and post in this thread if I need further help 🙂

If it works out, I’ll let you know and close this out.

Thanks again!
