# How can I add previous results in a line chart to new results

**URL:** https://discuss.elastic.co/t/how-can-i-add-previous-results-in-a-line-chart-to-new-results/215762
**Category:** Kibana
**Created:** [January 20, 2020, 3:04pm UTC](https://discuss.elastic.co/t/how-can-i-add-previous-results-in-a-line-chart-to-new-results/215762 "2020-01-20T15:04:01Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![111249](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/111249/32/58382_2.png) [@111249](https://discuss.elastic.co/u/111249)
#### Post date: [January 20, 2020, 3:04pm UTC](https://discuss.elastic.co/t/how-can-i-add-previous-results-in-a-line-chart-to-new-results/215762/1 "2020-01-20T15:04:01Z")

</div>

Hello. For example, I have a graph that shows the number of products added to the supermarket. I added 20 products in the first hour, 5 products in the second hour and 8 products in the third hour. I want to combine each point with the results of the previous points. First point must be 20 (for the first hour), second point must be 20 + 5 = 25 (for the second hour) and third point must be 20 + 5 + 8 = 32 (for the third hour). How can I do this?

Thanks.

---

<div class="post-metadata">

### Author: ![tiagocosta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tiagocosta/32/40045_2.png) [@tiagocosta](https://discuss.elastic.co/u/tiagocosta)
#### Post date: [January 20, 2020, 5:23pm UTC](https://discuss.elastic.co/t/how-can-i-add-previous-results-in-a-line-chart-to-new-results/215762/2 "2020-01-20T17:23:16Z")

</div>

Hi @111249,

I think for this you can use timelion with the following expression: `.es(index={INDEX_PATTERN}, timefield=date, metric=cardinality:{METRIC_NAME}).cusum()`

Cheers

---

<div class="post-metadata">

### Author: ![111249](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/111249/32/58382_2.png) [@111249](https://discuss.elastic.co/u/111249)
#### Post date: [January 21, 2020, 8:52am UTC](https://discuss.elastic.co/t/how-can-i-add-previous-results-in-a-line-chart-to-new-results/215762/3 "2020-01-21T08:52:13Z")

</div>

Thank you for answer @tiagocosta . I made this expression: `.es(split=supermarket:7, timefield=lastScraped, index=test*)`. End I got this result: [https://prnt.sc/qqmxhr](https://prnt.sc/qqmxhr)

I don't know what I need to use as {METRIC\_NAME}, because I want make sum of the count by time. I need get something like this: [https://prnt.sc/qqn2zt](https://prnt.sc/qqn2zt)  
How I can do this?

---

<div class="post-metadata">

### Author: ![tiagocosta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tiagocosta/32/40045_2.png) [@tiagocosta](https://discuss.elastic.co/u/tiagocosta)
#### Post date: [January 21, 2020, 5:49pm UTC](https://discuss.elastic.co/t/how-can-i-add-previous-results-in-a-line-chart-to-new-results/215762/4 "2020-01-21T17:49:24Z")

</div>

@111249 could u try to add `.cusum()` at the end of your current expression?

---

<div class="post-metadata">

### Author: ![111249](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/111249/32/58382_2.png) [@111249](https://discuss.elastic.co/u/111249)
#### Post date: [January 22, 2020, 10:41am UTC](https://discuss.elastic.co/t/how-can-i-add-previous-results-in-a-line-chart-to-new-results/215762/5 "2020-01-22T10:41:42Z")

</div>

Thank you so much, it helped

---

<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 19, 2020, 10:41am UTC](https://discuss.elastic.co/t/how-can-i-add-previous-results-in-a-line-chart-to-new-results/215762/6 "2020-02-19T10:41:43Z")

</div>

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