# How to calculate cumulative sum on date/time difference?

**URL:** https://discuss.elastic.co/t/how-to-calculate-cumulative-sum-on-date-time-difference/275707
**Category:** Kibana
**Created:** [June 11, 2021, 5:52pm UTC](https://discuss.elastic.co/t/how-to-calculate-cumulative-sum-on-date-time-difference/275707 "2021-06-11T17:52:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![nilei](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nilei/32/90186_2.png) [@nilei](https://discuss.elastic.co/u/nilei)
#### Post date: [June 11, 2021, 5:52pm UTC](https://discuss.elastic.co/t/how-to-calculate-cumulative-sum-on-date-time-difference/275707/1 "2021-06-11T17:52:54Z")

</div>

Dear all,

I have documents in my index with two Date/Time fields: "Created" and "Closed". Now I want to know how many documents exist at a time on a timeline where the relative time, that is the one currently displayed/calculated on the timeline, is between these two values. So the number of documents that were created but not yet closed at that time (let's say "Open" for this, where "Open" is not a field in the index).

So for example these three documents:

**Document 1:**  
Created: 2020-01-01  
Closed: 2020-07-01  
=\> Open: Q1-2020, Q2-2020, Q3-2020

**Document 2:**  
Created: 2020-05-01  
Closed: 2021-01-01  
=\> Open: Q2-2020, Q3-2020, Q4-2020

**Document 3:**  
Created: 2020-08-01  
Closed: 2021-04-01  
=\> Open: Q3-2020, Q4-2020, Q1-2021, Q2-2021

On a timeline with an interval of 1 quarter (in reality I will need an hourly representation afterwards) I then need the following result:

Q1-2020: 1 (Document 1)  
Q2-2020: 2 (Document 1 and 2)  
Q3-2020: 3 (document 1, 2 and 3)  
Q4-2020: 2 (document 2 and 3)  
Q1-2021: 1 (document 3)

So I think (not sure) that I need a cumulative total, but counting the documents where the create timestamp is less than and the closed timestamp is greater than the time on the timeline. And this is for each time point on the timeline.

Unfortunately, we **cannot** use Timelion. So the calculation should be possible through the other tools in Kibana. I have tried to work with sub-buckets and other tools, but have not been successful so far.

Thanks for your help and have a nice evening 🙂

---

<div class="post-metadata">

### Author: ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)
#### Post date: [June 14, 2021, 2:34pm UTC](https://discuss.elastic.co/t/how-to-calculate-cumulative-sum-on-date-time-difference/275707/2 "2021-06-14T14:34:16Z")

</div>

I would suggest looking at ESSQL in Canvas as a solution for this. Can't see a way of achieving it somewhere else without multiple scripted fields.

---

<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: [July 12, 2021, 2:35pm UTC](https://discuss.elastic.co/t/how-to-calculate-cumulative-sum-on-date-time-difference/275707/3 "2021-07-12T14:35:12Z")

</div>

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