# Using workpad variables in esql queries

**URL:** <https://discuss.elastic.co/t/using-workpad-variables-in-esql-queries/284235>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [September 15, 2021, 2:28am UTC](https://discuss.elastic.co/t/using-workpad-variables-in-esql-queries/284235 "2021-09-15T02:28:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![IGB042](https://avatars.discourse-cdn.com/v4/letter/i/ecc23a/32.png) [@IGB042](https://discuss.elastic.co/u/IGB042)\
**Post date:** [September 15, 2021, 2:28am UTC](https://discuss.elastic.co/t/using-workpad-variables-in-esql-queries/284235/1 "2021-09-15T02:28:08Z")

</div>

I am developing a report in Canvas currently and several elements use the same field within their esql queries. As it is intended that this workpad would be cloned it would be really useful to use a variable in the query

Currently I have

```auto
essql 
  query="SELECT HISTOGRAM(isotimestamp, INTERVAL 1 DAY) AS day, COUNT(result) AS tot, result AS res FROM \"MyIndex*\" WHERE account_id='DADCCUT3D44UOUCE9VDU' AND result='success' GROUP BY day, res"

```

I would prefer

```auto
account_id='{var \"AcctID\"}'

```

But I cannot get this to work. As the report queries multiple indexes for multiple elements it would be beneficial to be able to update this in one spot, rather than risk missing the change on one element.

---

<div class="post-metadata">

**Author:** ![corey.robertson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/corey.robertson/32/54611_2.png) [@corey.robertson](https://discuss.elastic.co/u/corey.robertson)\
**Post date:** [September 22, 2021, 1:16pm UTC](https://discuss.elastic.co/t/using-workpad-variables-in-esql-queries/284235/2 "2021-09-22T13:16:20Z")

</div>

Hi @IGB042

You'll have to use string concatenation to get the variable into the query.

So it would look something like

```auto
essql query={
  string "select * from MyIndex where account_id='" {var name="AcctID"} "'"
}

```

---

<div class="post-metadata">

**Author:** ![IGB042](https://avatars.discourse-cdn.com/v4/letter/i/ecc23a/32.png) [@IGB042](https://discuss.elastic.co/u/IGB042)\
**Post date:** [September 22, 2021, 10:51pm UTC](https://discuss.elastic.co/t/using-workpad-variables-in-esql-queries/284235/3 "2021-09-22T22:51:54Z")

</div>

Awesome Corey, did find I can drop the name= from the expression.

This is going to simplify the report creation process so much.

---

<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:** [October 20, 2021, 10:52pm UTC](https://discuss.elastic.co/t/using-workpad-variables-in-esql-queries/284235/4 "2021-10-20T22:52:12Z")

</div>

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