# Variable addition

**URL:** https://discuss.elastic.co/t/variable-addition/261139
**Category:** Kibana
**Created:** [January 14, 2021, 2:49pm UTC](https://discuss.elastic.co/t/variable-addition/261139 "2021-01-14T14:49:21Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![John\_H](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/john_h/32/82248_2.png) [@John\_H](https://discuss.elastic.co/u/John_H)
#### Post date: [January 14, 2021, 2:49pm UTC](https://discuss.elastic.co/t/variable-addition/261139/1 "2021-01-14T14:49:21Z")

</div>

I want to add up a number and show it in a kibana timeline chart.  
I've got a datastream which has a connect and disconnect entry. I've written a scripted field in kibana index which adds 1 when its connected to and substracts 1 when it's disconnected. So, I want a timeline chart to show how many connections there are over time by adding up the 1 and -1 e.g. it will be 0, 1, 2, 3, 2, 3, 2, 1, 0 as connections come and go. I can't figure out how toshow this though in a chart. I've looked timelion as well which has the concept of cusum which seems close but can't get that to work either. what I need is some kind of variable that gets stored over calls to the scripted field - but that doesn't look supported.  
any ideas?

thanks,  
john.

---

<div class="post-metadata">

### Author: ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)
#### Post date: [January 14, 2021, 3:48pm UTC](https://discuss.elastic.co/t/variable-addition/261139/2 "2021-01-14T15:48:45Z")

</div>

Hi @John_H,  
I think your description is a case for a cumulative sum, could you check that option?  
For example, for vertical bar chart: On Y axis you need to create a cumulative sum of a number field you want to track, and on x axis you create date histogram. Let me know if you need further guidance.

---

<div class="post-metadata">

### Author: ![John\_H](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/john_h/32/82248_2.png) [@John\_H](https://discuss.elastic.co/u/John_H)
#### Post date: [January 21, 2021, 2:02pm UTC](https://discuss.elastic.co/t/variable-addition/261139/3 "2021-01-21T14:02:09Z")

</div>

Ah ha - that worked - thankyou !  
I had a few issues with my data and I didn't realise that cumulative sum was available when not using a Timelion chart. Thank you 🙂

---

<div class="post-metadata">

### Author: ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)
#### Post date: [January 21, 2021, 2:54pm UTC](https://discuss.elastic.co/t/variable-addition/261139/4 "2021-01-21T14:54:28Z")

</div>

Great! I'm glad it worked! 🚀

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [February 18, 2021, 3:30pm UTC](https://discuss.elastic.co/t/variable-addition/261139/6 "2021-02-18T15:30:45Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
