# Bar chart based on cumulative function

**URL:** https://discuss.elastic.co/t/bar-chart-based-on-cumulative-function/212355
**Category:** Kibana
**Tags:** canvas
**Created:** [December 18, 2019, 3:26pm UTC](https://discuss.elastic.co/t/bar-chart-based-on-cumulative-function/212355 "2019-12-18T15:26:48Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![wadhah](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wadhah](https://discuss.elastic.co/u/wadhah)
#### Post date: [December 18, 2019, 3:26pm UTC](https://discuss.elastic.co/t/bar-chart-based-on-cumulative-function/212355/1 "2019-12-18T15:26:48Z")

</div>

Hello all,

I have an index "consump" having as fields : category, timestamp, costs.  
I want to display in Kibana Canvas, a bar chart exhibiting cumulative sum(costs).  
In other cases I used "timelion" for that like this: "

timelion  
query=".es(index=consumption\*, metric=sum:COSTS, timefield=@timestamp).cusum()" interval="1d" from="now-1M" to="now"

"

The problem in this case is that calculating the sum(costs) is not straight forward : for example if I need to calculate the SUM(costs) of the current month I need to do such query(since it is a blended cost):

essql  
query="SELECT MAX(costs)  
AS costs  
FROM "consump\*"  
WHERE MONTH("@timestamp")=MONTH(CURRENT\_DATE())  
GROUP BY "category""  
| math "round(sum(costs),2)"

 ![Capture](https://us1.discourse-cdn.com/elastic/original/3X/7/1/71c2b486894505f368f6721086d0adea38564d83.png)

So, here in this case the sum of the costs will be equal to 5+6+2=13

I want to build a bar chart where : y\_axis=cummulative\_sum(costs) and x\_axis=timestamp

So, can you please help me on how to proceed with such case.

---

<div class="post-metadata">

### Author: ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)
#### Post date: [December 18, 2019, 3:59pm UTC](https://discuss.elastic.co/t/bar-chart-based-on-cumulative-function/212355/2 "2019-12-18T15:59:06Z")

</div>

@tims @Catherine_Liu can we get some help? Thanks!

---

<div class="post-metadata">

### Author: ![wadhah](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wadhah](https://discuss.elastic.co/u/wadhah)
#### Post date: [December 18, 2019, 4:10pm UTC](https://discuss.elastic.co/t/bar-chart-based-on-cumulative-function/212355/3 "2019-12-18T16:10:44Z")

</div>

Thanks @bhavyarm for your quick interaction

---

<div class="post-metadata">

### Author: ![tims](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tims/32/46750_2.png) [@tims](https://discuss.elastic.co/u/tims)
#### Post date: [December 18, 2019, 5:42pm UTC](https://discuss.elastic.co/t/bar-chart-based-on-cumulative-function/212355/4 "2019-12-18T17:42:14Z")

</div>

Hi @wadhah, I'm not sure I'm completely following your example but have you tried using [mapColumn](https://www.elastic.co/guide/en/kibana/current/canvas-function-reference.html#mapColumn_fn) to calculate your cumulative sum?

---

<div class="post-metadata">

### Author: ![wadhah](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wadhah](https://discuss.elastic.co/u/wadhah)
#### Post date: [December 18, 2019, 6:01pm UTC](https://discuss.elastic.co/t/bar-chart-based-on-cumulative-function/212355/5 "2019-12-18T18:01:29Z")

</div>

Hey @tims : Thank you for your response.  
Actually, I gave a wrong example.  
Please find below the right one:

 ![Capture](https://us1.discourse-cdn.com/elastic/original/3X/0/0/00ab5899f216566b0b6283f8fd30dfa3201c63cf.png)

So, basically here, for example, for the category "c" : between the 1st and the 15th day, it hasn't consumed money as the costs remained at 1$. However, between the 15th and the 20th day it has consumed 1$. Same for "a" : between 1st and 15th day, it consumed 1$ and between 15th and 20th day, it consumed 4$.  
I hope this makes the picture clear.  
I tried to use mapColumn, but it did not work for me.

---

<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: [January 15, 2020, 6:01pm UTC](https://discuss.elastic.co/t/bar-chart-based-on-cumulative-function/212355/6 "2020-01-15T18:01:37Z")

</div>

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