# Sum with a condition

**URL:** <https://forums.losant.com/t/sum-with-a-condition/4741>\
**Category:** Help\
**Tags:** experience, workflow\
**Created:** [September 26, 2022, 10:39pm UTC](https://forums.losant.com/t/sum-with-a-condition/4741 "2022-09-26T22:39:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cesar\_Guedes](https://avatars.discourse-cdn.com/v4/letter/c/e68b1a/32.png) [@Cesar\_Guedes](https://forums.losant.com/u/Cesar_Guedes)\
**Post date:** [September 26, 2022, 10:39pm UTC](https://forums.losant.com/t/sum-with-a-condition/4741/1 "2022-09-26T22:39:27Z")

</div>

Hi!  
Inside an experience workflow, is it possible to get the sum of all values in a time range with a condition?

Clarifying:

- I have a device, sending a value X and a value Y every hour;
- By accessing an endpoint, the experience page shows me the sum of all X in a month (a simple gauge query with a time range);
- I want it to show me the sum of all X everytime Y was a specific value (Y\< 1,0 for example)

A few issues i’ve encountered:

- A simple Conditional Node wouldn’t work, because the trigger is the endpoint, so it would check the Y value just once. Not sure if a Loop node would solve this problem;
- In a regular workflow, a timer+conditional+gauge and a storage set would be enough, but there’s no timer in an experience workflow;
- I believe a Function Node would do the trick, but i’m trying to be as didactic as possible with this application, so it’s better if other nodes are able to perform what I want.

Any simple possibilities i’m missing?  
Appreciate the help!

---

<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:** [September 27, 2022, 1:32pm UTC](https://forums.losant.com/t/sum-with-a-condition/4741/2 "2022-09-27T13:32:16Z")

</div>

There isn’t an easy way to accomplish this for data that has already been reported. However, going forward, you could start saving a [new attribute](https://docs.losant.com/workflows/data/update-device/#individual-fields) (i.e. “xWhenYMeetsCondition”) on the device whenever it [reports state](https://docs.losant.com/workflows/triggers/device/) and only record that value when your [conditions](https://docs.losant.com/workflows/logic/conditional/) are met. You can then view these values in a relevant dashboard block. Here’s a basic sequence of nodes that would facilitate that:

 ![Screen Shot 2022-09-27 at 09.24.33](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/5/5e7ed92e597b4565961f4303385a02cb5aeb7d54.png)

Let us know how it goes, or if you have any questions!

---

<div class="post-metadata">

**Author:** ![Cesar\_Guedes](https://avatars.discourse-cdn.com/v4/letter/c/e68b1a/32.png) [@Cesar\_Guedes](https://forums.losant.com/u/Cesar_Guedes)\
**Post date:** [September 27, 2022, 7:40pm UTC](https://forums.losant.com/t/sum-with-a-condition/4741/3 "2022-09-27T19:40:50Z")

</div>

Excellent advice, Sebastian!  
I made something like this:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/9/97ae53dd3eed25b72bd65465902cc884ab5de3e1.png)  
and it seems to be doing the trick.

Thanks for helping, and please let me know if I’ll run into any trouble that i’m not seeing right now 😄
