# Variable based on variable

**URL:** <https://community.grafana.com/t/variable-based-on-variable/50112>\
**Category:** Grafana\
**Created:** [July 7, 2021, 1:28pm UTC](https://community.grafana.com/t/variable-based-on-variable/50112 "2021-07-07T13:28:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fsb](https://avatars.discourse-cdn.com/v4/letter/f/9fc29f/32.png) [@fsb](https://community.grafana.com/u/fsb)\
**Post date:** [July 7, 2021, 1:28pm UTC](https://community.grafana.com/t/variable-based-on-variable/50112/1 "2021-07-07T13:28:46Z")

</div>

Using Grafana 7 and Prometheus I would like to implement a dashboard and panel that allows the user to select a $step out of “1h”, “1d”, “1M” independent from the dashboard interval. I use an according interval variable for this purpose.

Derived from this variable I need a second variable, let’s call it $nhours, that represents the length of $step in hours (e.g. 24 in case of $step==1d).

This is the concrete purpose: I have a “my\_power” time series that represents power measurements (in W). I want to derive a rough estimate of energy bars (in kWh) $step by $step like this:

0.001 \* $nhours \* (avg\_over\_time(my\_power[$step]))

Intuitively, I would write the query like this, but it seems to be not possible to put time ranges into a PromQL expression:

0.001 \* ($nstep/24h) \* (avg\_over\_time(my\_power[$step]))

Any advice to a newbie?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/grafana/original/2X/e/ef5308cc58c9e5a13187b5012eb99f406928462f.png) [@system](https://community.grafana.com/u/system)\
**Post date:** [July 7, 2022, 1:29pm UTC](https://community.grafana.com/t/variable-based-on-variable/50112/2 "2022-07-07T13:29:07Z")

</div>

This topic was automatically closed after 365 days. New replies are no longer allowed.
