# Use var\_set in markdown and conditional coloring for markdown

**URL:** <https://discuss.elastic.co/t/use-var-set-in-markdown-and-conditional-coloring-for-markdown/266110>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [March 3, 2021, 12:55pm UTC](https://discuss.elastic.co/t/use-var-set-in-markdown-and-conditional-coloring-for-markdown/266110 "2021-03-03T12:55:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Clarke](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mike_clarke/32/87948_2.png) [@Mike\_Clarke](https://discuss.elastic.co/u/Mike_Clarke)\
**Post date:** [March 3, 2021, 12:55pm UTC](https://discuss.elastic.co/t/use-var-set-in-markdown-and-conditional-coloring-for-markdown/266110/1 "2021-03-03T12:55:33Z")

</div>

I am attempting to do the following:

```auto
var_set name="total" value={filters | timefilter column="createDate" from ={string "now-" {var "queryTimeframe"} "h"} to="now" | escount index"queries*" query="source:test"}
| var_set name="error" value={filters | timefilter column="createDate" from ={string "now-" {var "queryTimeframe"} "h"} to="now" | escount index"queries*" query="source:test AND (status:error or status:cancelled)"}
| var_set name="errorPct" value={math {string value={var "error"} value=" /" value={var "total"}}}
| markdown {var "total"} " Errored queries in " {var "queryTimeframe"} " hrs"
  font={font size=14 family="'Open Sans', Helvetica, Arial, sans-serif" color={if {var "errorPct"} {gt 0.3} then "red" else "green"} align="left"
| render
```

But this isn't working. How can I use one of the variables in the Markdown element and then a different variable in the 'if' statement?

---

<div class="post-metadata">

**Author:** ![Vadims\_Daleckis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vadims_daleckis/32/57613_2.png) [@Vadims\_Daleckis](https://discuss.elastic.co/u/Vadims_Daleckis)\
**Post date:** [March 3, 2021, 2:37pm UTC](https://discuss.elastic.co/t/use-var-set-in-markdown-and-conditional-coloring-for-markdown/266110/2 "2021-03-03T14:37:35Z")

</div>

Hi @Mike_Clarke,

I haven't tested your expression, but at first glance, it seems that the `if` function might be used incorrectly. In expressions it is possible to omit the default parameter name and immediately write the value, this is what you are doing in the `if` function, but it seems you are providing the default parameter twice.

```auto
{var "errorPct"} {gt 0.3}

```

Would it solve your problem if you provided a single default parameter, something like this:

```auto
if {var "errorPct" | gt 0.3} then="red" else="green"

or 

if condition={var "errorPct" | gt 0.3} then="red" else="green"

```

---

<div class="post-metadata">

**Author:** ![Mike\_Clarke](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mike_clarke/32/87948_2.png) [@Mike\_Clarke](https://discuss.elastic.co/u/Mike_Clarke)\
**Post date:** [March 3, 2021, 7:59pm UTC](https://discuss.elastic.co/t/use-var-set-in-markdown-and-conditional-coloring-for-markdown/266110/3 "2021-03-03T19:59:21Z")

</div>

@Vadims_Daleckis Thanks for the response and it seems to have fixed my conditional however I realized that neither `var_set` is being calculated correctly. I tried simplifying to something like this:

```
var_set name="total" value={filters | timefilter column="createDate" from ={string "now-" {var "queryTimeframe"} "h"} to="now" | escount index"queries*" query="source:test"}
| var_set name="error" value={filters | timefilter column="createDate" from ={string "now-" {var "queryTimeframe"} "h"} to="now" | escount index"queries*" query="source:test AND (status:error or status:cancelled)"}
| markdown {var "error"} " errors out of " {var "total"} " total queries"
| render

```

And the output is `0 errors out of 0 total queries`. Both of those values are greater than 0.

---

<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 31, 2021, 7:59pm UTC](https://discuss.elastic.co/t/use-var-set-in-markdown-and-conditional-coloring-for-markdown/266110/4 "2021-03-31T19:59:53Z")

</div>

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