# Canvas time filter

**URL:** https://discuss.elastic.co/t/canvas-time-filter/277420
**Category:** Kibana
**Created:** [June 30, 2021, 6:59am UTC](https://discuss.elastic.co/t/canvas-time-filter/277420 "2021-06-30T06:59:45Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Mik\_a](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mik_a/32/78256_2.png) [@Mik\_a](https://discuss.elastic.co/u/Mik_a)
#### Post date: [June 30, 2021, 6:59am UTC](https://discuss.elastic.co/t/canvas-time-filter/277420/1 "2021-06-30T06:59:46Z")

</div>

I made a Canvas workpad showing one metric. I need dynamic filters and if I import a filter from the dashboard they seem to have no effect.  
When I add a time filter from canvas "add element" my metric says "Error cannot divide by 0"  
Where can I find configuration for the filters?  
How do I attach them to the metrics (and charts)? Do they all need to be attached separetly?

---

<div class="post-metadata">

### Author: ![Felix\_Roessel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felix_roessel/32/41623_2.png) [@Felix\_Roessel](https://discuss.elastic.co/u/Felix_Roessel)
#### Post date: [June 30, 2021, 10:49am UTC](https://discuss.elastic.co/t/canvas-time-filter/277420/2 "2021-06-30T10:49:47Z")

</div>

In Canvas you have two dynamic filters.  
For is for the time. And one is for specific field values called the dropdown filter.  
If you just add those, each visualization and metric will get effected.. also from other slides. But you can define filter groups. A Filter group usually has a couple of filters + corresponding visualizations.

You see devide by zero most likely because your metric is based on a calculation. Maybe the number of rows that can be zero for the given time interval.

---

<div class="post-metadata">

### Author: ![Mik\_a](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mik_a/32/78256_2.png) [@Mik\_a](https://discuss.elastic.co/u/Mik_a)
#### Post date: [June 30, 2021, 12:32pm UTC](https://discuss.elastic.co/t/canvas-time-filter/277420/3 "2021-06-30T12:32:06Z")

</div>

Yes it is based on calculation. However, I tried with all time. ie. many years back so it cannot be completely zero

---

<div class="post-metadata">

### Author: ![Mik\_a](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mik_a/32/78256_2.png) [@Mik\_a](https://discuss.elastic.co/u/Mik_a)
#### Post date: [June 30, 2021, 12:50pm UTC](https://discuss.elastic.co/t/canvas-time-filter/277420/4 "2021-06-30T12:50:09Z")

</div>

I'm trying to implement another filter too and I think I knw where the issue is.  
In my calculations I use two different indecies. Now when I make a fillter it filters on both of them, But it should only filter on the first essql value in my calculation.

Can you help me achieve this please? If I somehow wrap everything in an if statement and the filter adds there the value or something. Changing the global variables or something?

---

<div class="post-metadata">

### Author: ![Felix\_Roessel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felix_roessel/32/41623_2.png) [@Felix\_Roessel](https://discuss.elastic.co/u/Felix_Roessel)
#### Post date: [June 30, 2021, 1:43pm UTC](https://discuss.elastic.co/t/canvas-time-filter/277420/5 "2021-06-30T13:43:34Z")

</div>

I can try to help, but need a bit more context.  
How is your expression incl. the calculation look like? Which filters are on the board?  
Whats the overall use case you would like to achive and so on.  
Of you need more examples you can look into [Kibana dashboard and canvas gallery](https://elastic-content-share.eu/downloads/category/kibana/)

---

<div class="post-metadata">

### Author: ![Mik\_a](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mik_a/32/78256_2.png) [@Mik\_a](https://discuss.elastic.co/u/Mik_a)
#### Post date: [July 1, 2021, 12:06pm UTC](https://discuss.elastic.co/t/canvas-time-filter/277420/6 "2021-07-01T12:06:52Z")

</div>

Time filter is one issue that I am skipping perhaps.  
How ever I am trying the other issue now.  
How do I put a global variable inside the query  
The code below works, but I need to use variable instead of hard coded "id" ("abc")

and on top of that I need to use global variable set in the UI and not in the expression editor.  
If not possible then I can use the drop down for this. but atm I do not know how to exchange this for that either

```auto
| var_set name="id" value="abc"
| var_set name="myvar" value={filters | essql query="SELECT COUNT(customer._id) AS buyers FROM \"visitors*\" WHERE (customer.group.id.keyword) = 'abc' " }
| math 
  {string "visitors/" {filters | var "myvar" | math "sum(buyers)"}}

```

---

<div class="post-metadata">

### Author: ![Felix\_Roessel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felix_roessel/32/41623_2.png) [@Felix\_Roessel](https://discuss.elastic.co/u/Felix_Roessel)
#### Post date: [July 1, 2021, 6:35pm UTC](https://discuss.elastic.co/t/canvas-time-filter/277420/7 "2021-07-01T18:35:48Z")

</div>

For the query parameter you open a new expression using curly brackets and in this expression you define the string including the query and the variable.

Here you have a couple of examples

> **[APM Services overview canvas dashboard at elastic content share](https://elastic-content-share.eu/downloads/apm-services-overview-canvas/)**
>
> The APM services canvas is an adaptive canvas board that fits to your APM data. If you running Elastic APM -- try it for free!

---

<div class="post-metadata">

### Author: ![Mik\_a](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mik_a/32/78256_2.png) [@Mik\_a](https://discuss.elastic.co/u/Mik_a)
#### Post date: [July 2, 2021, 6:28am UTC](https://discuss.elastic.co/t/canvas-time-filter/277420/8 "2021-07-02T06:28:49Z")

</div>

ok, thanks. I will check. I would prefer not to upload anything. But since googling for snippets and examples bear no fruit, I do appreciate this.

---

<div class="post-metadata">

### Author: ![Felix\_Roessel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felix_roessel/32/41623_2.png) [@Felix\_Roessel](https://discuss.elastic.co/u/Felix_Roessel)
#### Post date: [July 2, 2021, 6:47am UTC](https://discuss.elastic.co/t/canvas-time-filter/277420/9 "2021-07-02T06:47:16Z")

</div>

This is from the example:

```auto
var_set "row" value=1

| filters

  | essql query="SELECT service.name, Replace(service.name, ' ' , '%20') as appNameURL FROM \"apm*\" where service.name is not null group by service.name"

  | var_set "appName" value={if condition={rowCount | gt {var "row"}} then={getCell row={var "row"} column="service.name"} else={string ""}}

  | var_set "appNameURL" value={if condition={rowCount | gt {var "row"}} then={getCell row={var "row"} column="appNameURL"} else={string ""}}

| filters

  | essql query={string "SELECT service.name FROM \"apm*\" where service.name = '" {var appName} "' and processor.event = 'transaction' and transaction.duration.us > 2 "}

  | var_set name="count" value={rowCount }

  | var_set name="color" value={var "count" | if condition={eq 0} then="#AAAAAA" else="#f2bc33"}

```

---

<div class="post-metadata">

### Author: ![Mik\_a](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mik_a/32/78256_2.png) [@Mik\_a](https://discuss.elastic.co/u/Mik_a)
#### Post date: [July 2, 2021, 7:18am UTC](https://discuss.elastic.co/t/canvas-time-filter/277420/10 "2021-07-02T07:18:23Z")

</div>

hey I found one of my issues. my id begins with digit, so I need to define  
`var_set name="id" value="'123abc'"`

---

<div class="post-metadata">

### Author: ![Mik\_a](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mik_a/32/78256_2.png) [@Mik\_a](https://discuss.elastic.co/u/Mik_a)
#### Post date: [July 2, 2021, 7:27am UTC](https://discuss.elastic.co/t/canvas-time-filter/277420/11 "2021-07-02T07:27:34Z")

</div>

@Felix_Roessel thank you very much, you helped me with solution to my variabe issue. Although my original question is about time filtering so, I did not marke your last example as a solution.  
My next attempts are:

- changing global variable from drop down (is this even possible?)
- make the original q. time filter work 😃

---

<div class="post-metadata">

### Author: ![Felix\_Roessel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felix_roessel/32/41623_2.png) [@Felix\_Roessel](https://discuss.elastic.co/u/Felix_Roessel)
#### Post date: [July 2, 2021, 7:31am UTC](https://discuss.elastic.co/t/canvas-time-filter/277420/12 "2021-07-02T07:31:15Z")

</div>

No you cant change a global variable by dropdown. The dropdown is changing the filter context itself.  
I've created a [PR](https://github.com/elastic/kibana/pull/99761) to be able to set a default value in a dropdown. That helps to change the filters e.g. by using the `urlparam` functions

---

<div class="post-metadata">

### Author: ![Mik\_a](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mik_a/32/78256_2.png) [@Mik\_a](https://discuss.elastic.co/u/Mik_a)
#### Post date: [July 2, 2021, 7:48am UTC](https://discuss.elastic.co/t/canvas-time-filter/277420/13 "2021-07-02T07:48:36Z")

</div>

> [@Felix\_Roessel](#):
>
> filter context

ok good to know

---

<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: [July 30, 2021, 7:48am UTC](https://discuss.elastic.co/t/canvas-time-filter/277420/14 "2021-07-30T07:48:45Z")

</div>

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