# TSVB derivative returns 0 if previous interval was 0

**URL:** <https://discuss.elastic.co/t/tsvb-derivative-returns-0-if-previous-interval-was-0/252809>\
**Category:** Kibana\
**Created:** [October 21, 2020, 8:59am UTC](https://discuss.elastic.co/t/tsvb-derivative-returns-0-if-previous-interval-was-0/252809 "2020-10-21T08:59:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Duncan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_duncan/32/46467_2.png) [@Mark\_Duncan](https://discuss.elastic.co/u/Mark_Duncan)\
**Post date:** [October 21, 2020, 8:59am UTC](https://discuss.elastic.co/t/tsvb-derivative-returns-0-if-previous-interval-was-0/252809/1 "2020-10-21T08:59:50Z")

</div>

This dataset has values recorded on a Monday to Friday, and no data at weekends. The graph plots data per day/24 hours.

I've plotted a cumulative sum (blue line) and the value changes each weekday; as there is no data recorded on a Saturday or Sunday, the metric drops to 0 at weekends (as expected).

 ![Screenshot 2020-10-20 at 19.42.33](https://us1.discourse-cdn.com/elastic/original/3X/e/a/ea83aec411573f4f2c5813b700b07439effa174b.png)

However, a derivative metric (the pink bars) will only get plotted on a Tuesday to Friday. The highlighted day is a Monday and as you can see the pink bar derivative is 0.

I'd like to get the pink bars plotting for Mondays. An option that I can see would be to plot some summary values on a Saturday and Sunday to match Friday's final values - **would there be an automated way to do this? I don't think a transform would work?**

**Are there any other ideas how to get the derivative bars to plot when the previous intervals' data is 0?**

TIA  
Mark

---

<div class="post-metadata">

**Author:** ![monfera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/monfera/32/26467_2.png) [@monfera](https://discuss.elastic.co/u/monfera)\
**Post date:** [October 22, 2020, 10:54am UTC](https://discuss.elastic.co/t/tsvb-derivative-returns-0-if-previous-interval-was-0/252809/2 "2020-10-22T10:54:33Z")

</div>

Hello Mark, the setup is not fully clear to me. Often, one would have a baseline time series, and in addition to that, perhaps a difference (what Elasticsearch calls derivation). However you're making a reference to a cumulative sum (blue line). So, do you have a baseline time series, which you don't show, and two derived ones, a difference and a cumulative sum? Have you a screenshot of the full config?

---

<div class="post-metadata">

**Author:** ![Mark\_Duncan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_duncan/32/46467_2.png) [@Mark\_Duncan](https://discuss.elastic.co/u/Mark_Duncan)\
**Post date:** [November 5, 2020, 7:15pm UTC](https://discuss.elastic.co/t/tsvb-derivative-returns-0-if-previous-interval-was-0/252809/3 "2020-11-05T19:15:56Z")

</div>

> [@monfera](#):
>
> do you have a baseline time series, which you don't show, and two derived ones, a difference and a cumulative sum?

Hey Robert,

Yes, I have a baseline time series - not shown on the graph - and two derived metrics: **first** is a bucket script (containing a cumulative sum) and then summed in a Series Aggregation, and then the **second** in the screenshot is a derivative based on the cum sum.

 ![Screenshot 2020-11-05 at 19.03.35](https://us1.discourse-cdn.com/elastic/original/3X/4/e/4e17a2a3f2d9dfe396c30eb47c65c76a1c77b580.png)

I'm trying to solve with a Timelion graph - this formula below gives me 75 lines, but I cannot sum the 75 lines into 1 line using .sum() (the equivalent of the Series Aggregation in the TSVB graph). Any thoughts there?

Thanks Robert!

```
    .es(index=daily_summary_alpaca,timefield=recv_timestamp,metric=sum:buy_filled_size,split=instrument:100).cusum().subtract(
.es(index=daily_summary_alpaca,timefield=recv_timestamp,metric=sum:sell_filled_size,split=instrument:100).cusum())
.multiply(.es(index=daily_summary_alpaca,timefield=recv_timestamp,metric=avg:latest_price,split=instrument:100))

```

---

<div class="post-metadata">

**Author:** ![monfera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/monfera/32/26467_2.png) [@monfera](https://discuss.elastic.co/u/monfera)\
**Post date:** [November 9, 2020, 2:41pm UTC](https://discuss.elastic.co/t/tsvb-derivative-returns-0-if-previous-interval-was-0/252809/4 "2020-11-09T14:41:30Z")

</div>

Thanks for the added detail, Duncan, I understand your setup better now. Why do you say in your original post that the drop of the blue cumulative sum to zero at weekends is "as expected"? Is it not your expectation that as the base metric is zero, the cumulative sum stays level? I see on the chart that both the cumulative sum and the daily difference are zeros on weekends, which wouldn't be my expectation unless Friday already had a metric value of zero and a cumulative sum of also zero.

---

<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:** [December 7, 2020, 2:41pm UTC](https://discuss.elastic.co/t/tsvb-derivative-returns-0-if-previous-interval-was-0/252809/5 "2020-12-07T14:41:35Z")

</div>

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