# Timelion Sheet: is a secondary (TL-native) calculation possible

**URL:** <https://discuss.elastic.co/t/timelion-sheet-is-a-secondary-tl-native-calculation-possible/166568>\
**Category:** Kibana\
**Tags:** timelion\
**Created:** [January 31, 2019, 1:36pm UTC](https://discuss.elastic.co/t/timelion-sheet-is-a-secondary-tl-native-calculation-possible/166568 "2019-01-31T13:36:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mariner191](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Mariner191](https://discuss.elastic.co/u/Mariner191)\
**Post date:** [January 31, 2019, 1:36pm UTC](https://discuss.elastic.co/t/timelion-sheet-is-a-secondary-tl-native-calculation-possible/166568/1 "2019-01-31T13:36:07Z")

</div>

In Timelion is a secondary calculation possible? .trend () of .divide ().  
Stated differently, How to calculate trend of Percent, where Percent is calculated using .divide () in Timelion, and is not a Scripted Field.

 ![Elastic_Forum_Image_TrendofPercent](https://us1.discourse-cdn.com/elastic/original/3X/0/5/05c5790435f9e748784649101fbe891e64961908.jpeg)

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [January 31, 2019, 9:24pm UTC](https://discuss.elastic.co/t/timelion-sheet-is-a-secondary-tl-native-calculation-possible/166568/2 "2019-01-31T21:24:21Z")

</div>

I believe all you need here is to add a trend at the end. Here's an example, since I can't see what your exact query is:

```auto
 .es(q=error).divide(.es(q=*)).trend()

```

This will query error documents, divide them by the total and provide a percentage of errors, and then give you the linear regression of the percentage value over time.

---

<div class="post-metadata">

**Author:** ![Mariner191](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Mariner191](https://discuss.elastic.co/u/Mariner191)\
**Post date:** [February 1, 2019, 12:49pm UTC](https://discuss.elastic.co/t/timelion-sheet-is-a-secondary-tl-native-calculation-possible/166568/3 "2019-02-01T12:49:26Z")

</div>

Yes, while .trend() at end displays the linear regression line, we at the same time lose the .divide() tabulated Percent line of the raw data.

1. Is there a way to display both the tabulated Percent line and Trend in the same TL graph
2. Is there a Function for Polynomial Regression, or only Linear?

Thank you!

---

<div class="post-metadata">

**Author:** ![Mariner191](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Mariner191](https://discuss.elastic.co/u/Mariner191)\
**Post date:** [February 1, 2019, 12:59pm UTC](https://discuss.elastic.co/t/timelion-sheet-is-a-secondary-tl-native-calculation-possible/166568/4 "2019-02-01T12:59:51Z")

</div>

1. Resolved: At the end of the initial .es(q=error).divide(.es(q=_)) appended a complete .es(q=error).divide(.es(q=_)).trend(). This displays both Percent and Trend lines on the same graph

2. Is there a Function for Polynomial Regression, or only Linear?

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [February 11, 2019, 7:54pm UTC](https://discuss.elastic.co/t/timelion-sheet-is-a-secondary-tl-native-calculation-possible/166568/5 "2019-02-11T19:54:08Z")

</div>

As far as I know there's only a linear regression function, but I'm not the most well-versed Timelion user, so I could be wrong. I've asked someone else on the team that knows more about it, and I'll let you know what I learn.

* * *

UPDATE: poking through the code a little, it looks like `.trend()` has a logarithmic mode. I'm basing that on [this bit of code](https://github.com/elastic/kibana/blob/master/src/legacy/core_plugins/timelion/server/series_functions/trend/index.js#L25-L28), which define the valid values for `mode`.

* * *

UPDATE 2: perhaps you already know this, but just in case, you can find the trend function's docs here: [https://github.com/elastic/timelion/blob/master/FUNCTIONS.md#trend](https://github.com/elastic/timelion/blob/master/FUNCTIONS.md#trend)

---

<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:** [March 11, 2019, 8:03pm UTC](https://discuss.elastic.co/t/timelion-sheet-is-a-secondary-tl-native-calculation-possible/166568/6 "2019-03-11T20:03:33Z")

</div>

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