# Conditionals in Canvas

**URL:** <https://discuss.elastic.co/t/conditionals-in-canvas/168796>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [February 18, 2019, 9:47am UTC](https://discuss.elastic.co/t/conditionals-in-canvas/168796 "2019-02-18T09:47:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rozling](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rozling/32/16401_2.png) [@rozling](https://discuss.elastic.co/u/rozling)\
**Post date:** [February 18, 2019, 9:47am UTC](https://discuss.elastic.co/t/conditionals-in-canvas/168796/1 "2019-02-18T09:47:17Z")

</div>

Hi,

I'm creating a Canvas dashboard using data from the Heartbeat plugin, and using the opportunity to learn Canvas syntax.

I'm using an SQL query to pull the data from Heartbeat like so:

```
filters
| essql 
  query="SELECT \"@timestamp\", \"monitor.status\" FROM \"heartbeat*\" WHERE QUERY('service_name:my_service') ORDER BY \"@timestamp\" DESC LIMIT 1 "
| table
| render

```

This returns a table with timestamp and monitor.status as expected.

Now I want to change the text depending on the response; instead of `up` I want to see `Healthy`. I've seen this kind of thing done in other types of queries (mostly TimeLion) with switches, but I would also expect to be able to do something like this:

```
filters
| essql 
  query="SELECT \"@timestamp\", \"monitor.status\" FROM \"heartbeat*\" WHERE QUERY('service_name:my_service') ORDER BY \"@timestamp\" DESC LIMIT 1 "
| if {compare \"monitor.status\" to="up"} then ="healthy"
| table
| render

```

This breaks the visualization though. Can anyone advise or point me to examples where switches / conditionals are used with essql queries?

---

<div class="post-metadata">

**Author:** ![rozling](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rozling/32/16401_2.png) [@rozling](https://discuss.elastic.co/u/rozling)\
**Post date:** [February 18, 2019, 10:29am UTC](https://discuss.elastic.co/t/conditionals-in-canvas/168796/2 "2019-02-18T10:29:57Z")

</div>

Got it working as a switch! Here's the full query rendering to a markdown element:

```
filters
| essql 
  query="SELECT \"@timestamp\", \"monitor.status\" as status FROM \"heartbeat*\" WHERE QUERY('my_service') LIMIT 1"
| mapColumn value
  fn=${getCell status | switch 
    {case if={compare eq to="up"} then=Healthy}
    {case if={compare eq to="down"} then=Unhealthy}
    default="Unknown"
  }
| markdown "{{#each rows}}
# {{value}}
{{/each}}" 
  font={font family="'Open Sans', Helvetica, Arial, sans-serif" size=18 align="left" color="#000000" weight="bold" underline=false italic=false}
| render containerStyle={containerStyle}

```

(not sure the `{{#each rows}}` etc is necessary, happy to take advice on that.

Also FYI I got the answer from this blog post: [Canvas Blog Stream](https://discuss.elastic.co/t/canvas-blog-stream/126823/29?u=rozling)

And found examples here: [https://github.com/alexfrancoeur/kibana\_canvas\_examples](https://github.com/alexfrancoeur/kibana_canvas_examples)

---

<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 18, 2019, 10:30am UTC](https://discuss.elastic.co/t/conditionals-in-canvas/168796/3 "2019-03-18T10:30:03Z")

</div>

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