# Set static variable in essql

**URL:** <https://discuss.elastic.co/t/set-static-variable-in-essql/184607>\
**Category:** Kibana\
**Created:** [June 6, 2019, 2:34pm UTC](https://discuss.elastic.co/t/set-static-variable-in-essql/184607 "2019-06-06T14:34:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ofitz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ofitz/32/47071_2.png) [@ofitz](https://discuss.elastic.co/u/ofitz)\
**Post date:** [June 6, 2019, 2:34pm UTC](https://discuss.elastic.co/t/set-static-variable-in-essql/184607/1 "2019-06-06T14:34:00Z")

</div>

Hi everyone,

i have this query:

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

I would like to set in my `plot defaultStyle{...}...` the `axisConfig max=10` the `max` value from a variable as the number from `VALUE` variable from query.  
The 10 must not be static, it is possible?

thx.

---

<div class="post-metadata">

**Author:** ![lukeelmers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukeelmers/32/35230_2.png) [@lukeelmers](https://discuss.elastic.co/u/lukeelmers)\
**Post date:** [June 6, 2019, 6:43pm UTC](https://discuss.elastic.co/t/set-static-variable-in-essql/184607/2 "2019-06-06T18:43:15Z")

</div>

Currently, expressions do not have a concept of "variables" built into the grammar. Each function passes its output (`context`) to the next function in the expression, but there isn't a way to set a "global" variable within an expression.

There also isn't yet a way to deal with context that needs to be accessed by another function later in the expression. So in your example, there is no way for the `plot` function to access a value from the context returned by the `essql` function, because the only context it receives is the output of `pointseries`. We've been discussing ways this could potentially be resolved in the future.

In the meantime, you could try looking at the context returned from `pointseries` to see if the value you need is already contained there:

```auto
essql query="SELECT foo, bar FROM baz"
| pointseries x=foo y=bar
| render as=debug

```

If the debug shows you the value you need, you may be able to extract it as a subexpression using the `getCell` function, since `pointseries` returns a `datatable`. For example, if you needed to set `max` to be the first row returned in the `x` column, you could do something like this:

```auto
essql query="SELECT foo, bar FROM baz"
| pointseries x=foo y=bar
| plot yaxis={axisConfig position=left max={getCell column=x row=0}}

```

---

<div class="post-metadata">

**Author:** ![ofitz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ofitz/32/47071_2.png) [@ofitz](https://discuss.elastic.co/u/ofitz)\
**Post date:** [June 10, 2019, 10:18am UTC](https://discuss.elastic.co/t/set-static-variable-in-essql/184607/3 "2019-06-10T10:18:35Z")

</div>

Thx lekeelmers,

i tried it next time.

Can i create Doubles Bars in one Barchart, like one Bars is live Value and the other AVG Value bar. Like this screenshot: Blue is live Value and RED is AVG value of one sensor

 ![Screenshot_20190610-121151_Photos](https://us1.discourse-cdn.com/elastic/original/3X/1/6/1677128b50a9c0100c74459282ddd3e14130c882.jpeg)

---

<div class="post-metadata">

**Author:** ![lukeelmers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukeelmers/32/35230_2.png) [@lukeelmers](https://discuss.elastic.co/u/lukeelmers)\
**Post date:** [July 5, 2019, 6:44pm UTC](https://discuss.elastic.co/t/set-static-variable-in-essql/184607/4 "2019-07-05T18:44:22Z")

</div>

I don't think there's a way to accomplish what you are looking for with double bars showing different values, but you _might_ be able to do stacked bars depending on the shape of your data. See this thread for more details: [Canvas: how to make stacked area chart?](https://discuss.elastic.co/t/canvas-how-to-make-stacked-area-chart/180399)

---

<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:** [August 2, 2019, 6:44pm UTC](https://discuss.elastic.co/t/set-static-variable-in-essql/184607/5 "2019-08-02T18:44:24Z")

</div>

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