# How to manipulate result of cumulative sum metric?

**URL:** https://discuss.elastic.co/t/how-to-manipulate-result-of-cumulative-sum-metric/94063
**Category:** Kibana
**Created:** [July 21, 2017, 6:52am UTC](https://discuss.elastic.co/t/how-to-manipulate-result-of-cumulative-sum-metric/94063 "2017-07-21T06:52:05Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)
#### Post date: [July 21, 2017, 6:52am UTC](https://discuss.elastic.co/t/how-to-manipulate-result-of-cumulative-sum-metric/94063/1 "2017-07-21T06:52:05Z")

</div>

Kibana version : 5.4.0

Hello .

I have a goal to achieve but struggling with kibana interface so I would like to get some help with this.

## My Goal

I will need to achieve below 2 steps

1. Calculate the _cumulative sum_ of field _spamscore_ using the histogram bucket
2. Using the _cumulative sum_ I will need to calculate the ratio of against the _total hits_ of search period.

For step2 , I will need to divide each histogram bucket by _73_ (e.g 3 / 73 , 5/73,etc )

 ![](https://us1.discourse-cdn.com/elastic/original/3X/f/e/fe888b2e468eb203ef64595f5c5875cd6ea892fa.PNG)

Currently, I have achieved step1 as below.

 ![](https://us1.discourse-cdn.com/elastic/original/3X/e/d/ed9250379cbd0516631f83a389c0d88f1e12c989.png)

However, I am struggling with Step2. After reading the [document](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html) , I assume that I will need to write script but not sure **where to write it** and **how to access the cumulative sum series as doc field**.

May I ask how can I achieve my goal?

---

<div class="post-metadata">

### Author: ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)
#### Post date: [July 21, 2017, 8:56pm UTC](https://discuss.elastic.co/t/how-to-manipulate-result-of-cumulative-sum-metric/94063/2 "2017-07-21T20:56:50Z")

</div>

Unfortunately, you are not currently able to chain aggregations in Visualize. However, this might be possible with Timelion if you are actually looking for a histogram.

What should the visualization look like in the end?

@thomasneirynck might be able to provide some insights.

---

<div class="post-metadata">

### Author: ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)
#### Post date: [July 24, 2017, 1:45am UTC](https://discuss.elastic.co/t/how-to-manipulate-result-of-cumulative-sum-metric/94063/3 "2017-07-24T01:45:11Z")

</div>

@tsmalley

Thank you for the reply.

Ok. So input data will be below. _Score_ will be the histogram in this case.

![data_series](https://us1.discourse-cdn.com/elastic/original/3X/8/6/86199bbe6e9dde0783ea80f3422f4348d8975759.PNG)

From above time series , I want to do aggregation like below.

![](https://us1.discourse-cdn.com/elastic/original/3X/c/f/cf57d40615085a78e71b923171b0a68c7d595699.PNG)

From the data above I am trying to draw a chart like below. The charts consists of

1. Counts per scores
2. ratio of counts against cumulative sum of counts along the over the scores.

![](https://us1.discourse-cdn.com/elastic/original/3X/4/0/400b97f0e43cd56129b46865bc2ae1e40954e60c.PNG)

Can this be drawn on timelion ?

---

<div class="post-metadata">

### Author: ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)
#### Post date: [July 27, 2017, 8:19am UTC](https://discuss.elastic.co/t/how-to-manipulate-result-of-cumulative-sum-metric/94063/4 "2017-07-27T08:19:47Z")

</div>

@tsmalley @thomasneirynck

Any luck ?

---

<div class="post-metadata">

### Author: ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)
#### Post date: [August 7, 2017, 1:53am UTC](https://discuss.elastic.co/t/how-to-manipulate-result-of-cumulative-sum-metric/94063/5 "2017-08-07T01:53:28Z")

</div>

I have amended the original data series. Since it was the result aggregation instead.

---

<div class="post-metadata">

### Author: ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)
#### Post date: [August 10, 2017, 11:39am UTC](https://discuss.elastic.co/t/how-to-manipulate-result-of-cumulative-sum-metric/94063/6 "2017-08-10T11:39:21Z")

</div>

Any good idea?

---

<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: [September 7, 2017, 11:39am UTC](https://discuss.elastic.co/t/how-to-manipulate-result-of-cumulative-sum-metric/94063/7 "2017-09-07T11:39:22Z")

</div>

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