# Dashboard variables set dynamically from a query

**URL:** <https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507>\
**Category:** Kibana\
**Created:** [June 26, 2025, 8:16am UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507 "2025-06-26T08:16:34Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![tallakh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tallakh/32/8860_2.png) [@tallakh](https://discuss.elastic.co/u/tallakh)\
**Post date:** [June 26, 2025, 8:16am UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507/1 "2025-06-26T08:16:34Z")

</div>

Hi!  
I'm looking for a feature that I don't think is possible to do now, but I hope it will come in the future. We are using Kibana dashboards to get insights into our sales performance. I want to be able set a variable in the dashboard ( f ex total sales in this time range) and be able to use this variable in lens formulas to get share of sales. Is this something that will be possible with ESQL?

---

<div class="post-metadata">

**Author:** ![Tortoise](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tortoise/32/147587_2.png) [@Tortoise](https://discuss.elastic.co/u/Tortoise)\
**Post date:** [June 26, 2025, 8:25am UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507/2 "2025-06-26T08:25:37Z")

</div>

Hello @tallakh

Could you please try to provide an example for better clarity related to the requirement?

Thanks!!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 26, 2025, 8:41am UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507/3 "2025-06-26T08:41:38Z")

</div>

I'm doing something which looks a bit similar where I can select a field name from the dashboard and inject this field name in the ES|QL request.

```auto
FROM person 
| STATS count = COUNT() BY ??field
| LIMIT 100

```

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/b/9bfdb0b1289198671d8ddde12b25369670f4f2a3.png)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/e/eed8d9bbcfdbf69bfe653a25d040b5d06c7273f9.png)

I'm doing that in Elastic Serverless. Not sure if it's possible in 9.0. You might have to wait for 9.1???

IMHO it's a super nice feature that have been asked for years and is now here...

---

<div class="post-metadata">

**Author:** ![tallakh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tallakh/32/8860_2.png) [@tallakh](https://discuss.elastic.co/u/tallakh)\
**Post date:** [June 26, 2025, 9:48am UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507/4 "2025-06-26T09:48:40Z")

</div>

F ex in a lens table that has split rows on categories, I want to be able to show the share of total sales for each category. This is possible to an extent using a formula like sum(total\_revenue) / overall\_sum(sum(total\_revenue)) but that does not work when filtering down on one of the categories.

 ![Screenshot 2025-06-26 at 12.02.58](https://us1.discourse-cdn.com/elastic/original/3X/8/4/84b082f436afca2ba970cf45da87877578e2dad4.png)  
 ![Screenshot 2025-06-26 at 12.03.32](https://us1.discourse-cdn.com/elastic/original/3X/e/1/e14902857b2d8b876a45c6782e74bda0d537023e.png)

I think it would be very powerful to be able to set a dashboard variable like total\_sales = sum(total\_revenue) that ignore any filters, which can be used in a formula f ex sum(total\_revenue) / {{total\_sales}}

---

<div class="post-metadata">

**Author:** ![tallakh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tallakh/32/8860_2.png) [@tallakh](https://discuss.elastic.co/u/tallakh)\
**Post date:** [June 26, 2025, 9:51am UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507/5 "2025-06-26T09:51:41Z")

</div>

Thanks David, that looks super useful! I've been wondering if this feature would solve my need. But initially it doesn't look like it will. I'll have to play around with it.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 26, 2025, 6:13pm UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507/6 "2025-06-26T18:13:34Z")

</div>

Yeah. It's a bit new but it opens yet the door to new use cases.

---

<div class="post-metadata">

**Author:** ![tallakh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tallakh/32/8860_2.png) [@tallakh](https://discuss.elastic.co/u/tallakh)\
**Post date:** [July 2, 2025, 1:13pm UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507/7 "2025-07-02T13:13:36Z")

</div>

Hi again David! I'm trying to implement the field that you set and I'm not sure how I can do that. Is it a control element, or something else? I'm running elastic stack 9.2, and I fail to find documentation on this 🙂

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 2, 2025, 1:44pm UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507/8 "2025-07-02T13:44:54Z")

</div>

Yeah. It's a bit hidden IMO.  
I can find it when creating a dashboard, and adding a Panel ES|QL, then when writing the ES|QL query, it sometimes appears. See "Create control" in the above screenshot.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/5/857999804841d4e207e90eb412ffc74dcdd2917e.png)

Which gives at the end something like:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/9/39f70ce66c05dc541aded90622c728a177ac10cf.png)

HTH

BTW: I'm running a 9.0.1 version.

---

<div class="post-metadata">

**Author:** ![tallakh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tallakh/32/8860_2.png) [@tallakh](https://discuss.elastic.co/u/tallakh)\
**Post date:** [July 2, 2025, 2:08pm UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507/9 "2025-07-02T14:08:12Z")

</div>

Thanks! I found this [github PR](https://github.com/elastic/kibana/pull/202875) that explains the feature. Any idea on how to create a control that uses the values from a ES|QL result?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 2, 2025, 2:52pm UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507/10 "2025-07-02T14:52:37Z")

</div>

I don't know yet 😉

May be @Stratoula_Kalafateli could tell?

---

<div class="post-metadata">

**Author:** ![Stratoula\_Kalafateli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stratoula_kalafateli/32/70923_2.png) [@Stratoula\_Kalafateli](https://discuss.elastic.co/u/Stratoula_Kalafateli)\
**Post date:** [July 3, 2025, 2:29pm UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507/11 "2025-07-03T14:29:23Z")

</div>

You can start typing a query like

FROM index | WHERE field ==

and then select "Create control" and you will be able to write an ES|QL query to retrieve the values

---

<div class="post-metadata">

**Author:** ![tallakh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tallakh/32/8860_2.png) [@tallakh](https://discuss.elastic.co/u/tallakh)\
**Post date:** [July 30, 2025, 11:02am UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507/12 "2025-07-30T11:02:37Z")

</div>

Thanks!

Will this work in Kibana Maps ES|QL layers as well?

---

<div class="post-metadata">

**Author:** ![Stratoula\_Kalafateli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stratoula_kalafateli/32/70923_2.png) [@Stratoula\_Kalafateli](https://discuss.elastic.co/u/Stratoula_Kalafateli)\
**Post date:** [July 30, 2025, 12:24pm UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507/13 "2025-07-30T12:24:12Z")

</div>

For now (8.18, 8.19, 9.0 and 9.1) will be a dashboard thing and will work for ES|QL Lens charts.

Next thing in the roadmap is support in Discover and Discover sessions.

Maps are not in the immediate roadmap but we will definitely support them there.

---

<div class="post-metadata">

**Author:** ![tallakh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tallakh/32/8860_2.png) [@tallakh](https://discuss.elastic.co/u/tallakh)\
**Post date:** [September 17, 2025, 8:20am UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507/14 "2025-09-17T08:20:06Z")

</div>

Sorry for bringing back an old question, but I just wanted to say that having this functionality in maps as well would be extremely useful in our case. Any idea on when it would be available?

---

<div class="post-metadata">

**Author:** ![Stratoula\_Kalafateli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stratoula_kalafateli/32/70923_2.png) [@Stratoula\_Kalafateli](https://discuss.elastic.co/u/Stratoula_Kalafateli)\
**Post date:** [September 17, 2025, 10:13am UTC](https://discuss.elastic.co/t/dashboard-variables-set-dynamically-from-a-query/379507/15 "2025-09-17T10:13:39Z")

</div>

Hey! Supporting controls in maps made with ES|QL is not supported atm. We are evaluating if we can prioritize it atm. We will send an update the upcoming week
