# Dynamically change Moving Average (Timelion)

**URL:** https://discuss.elastic.co/t/dynamically-change-moving-average-timelion/251144
**Category:** Kibana
**Tags:** timelion
**Created:** [October 6, 2020, 2:30pm UTC](https://discuss.elastic.co/t/dynamically-change-moving-average-timelion/251144 "2020-10-06T14:30:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Max\_Handle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/max_handle/32/48133_2.png) [@Max\_Handle](https://discuss.elastic.co/u/Max_Handle)
#### Post date: [October 6, 2020, 2:30pm UTC](https://discuss.elastic.co/t/dynamically-change-moving-average-timelion/251144/1 "2020-10-06T14:30:55Z")

</div>

Hi,

Is there a way to dynamically change the moving average function in timelion. For example could I somehow write a conditional statement that references the selection of the time picker? So for example if the time picker is set to show the past 7 days then I want to have a moving avg of (2), whereas I would like to have a moving avg of (7) when the time picker includes a greater timeinterval than 7 days. Or generally is there a better workaround than this?

Thank you for your help!

Max

 ![Bildschirmfoto 2020-10-06 um 16.28.07](https://us1.discourse-cdn.com/elastic/original/3X/d/9/d9e5327fa573081204aab8c8ff05f23b6c5775a8.jpeg)

---

<div class="post-metadata">

### Author: ![cheiligers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cheiligers/32/73114_2.png) [@cheiligers](https://discuss.elastic.co/u/cheiligers)
#### Post date: [October 6, 2020, 5:59pm UTC](https://discuss.elastic.co/t/dynamically-change-moving-average-timelion/251144/2 "2020-10-06T17:59:49Z")

</div>

Hi @Max_Handle!  
The time picker only filters documents that are read from elasticsearch. What that means is that when the timepicker is set for the last 7 days, es queries only return the last 7 days of docs.

As for workarounds: you might be able to set the moving average value using a [conditional](https://www.elastic.co/guide/en/kibana/current/timelion.html#timelion-conditional-intro) on the date range for the documents you do return (filtered based off of the timepicker). There's also a blog post that looks like it could help: [https://www.elastic.co/blog/timeseries-if-then-else-with-timelion](https://www.elastic.co/blog/timeseries-if-then-else-with-timelion). Good luck!

---

<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: [November 3, 2020, 5:59pm UTC](https://discuss.elastic.co/t/dynamically-change-moving-average-timelion/251144/3 "2020-11-03T17:59:53Z")

</div>

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