# Variable not working

**URL:** <https://community.influxdata.com/t/variable-not-working/29795>\
**Category:** Systems\
**Created:** [May 5, 2023, 5:32am UTC](https://community.influxdata.com/t/variable-not-working/29795 "2023-05-05T05:32:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AVVS\_Sudheer](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/avvs_sudheer/32/13075_2.png) [@AVVS\_Sudheer](https://community.influxdata.com/u/AVVS_Sudheer)\
**Post date:** [May 5, 2023, 5:32am UTC](https://community.influxdata.com/t/variable-not-working/29795/1 "2023-05-05T05:32:00Z")

</div>

Hi,

Till yesterday afternoon variables are working fine in grafana with Influx as the backend data source. The query is as below

from(bucket: “bucketname”)  
|\> range(start: v.timeRangeStart, stop: v.timeRangeStop)  
|\> filter(fn:(r) =\>r[“\_measurement”] == “measurement”)  
|\> last()  
|\> group()  
|\> keyValues(keyColumns: [“column1”])  
|\> drop(columns:[“\_tag1”])

But from yesterday evening the above query is not working. I have data in that measurement. I am using Influx 2.1 version. Can anyone help me why this is happening

Regards  
Sudheer

---

<div class="post-metadata">

**Author:** ![fercasjr](https://avatars.discourse-cdn.com/v4/letter/f/e495f1/32.png) [@fercasjr](https://community.influxdata.com/u/fercasjr)\
**Post date:** [May 5, 2023, 2:00pm UTC](https://community.influxdata.com/t/variable-not-working/29795/2 "2023-05-05T14:00:11Z")

</div>

Is that the query to get the variable values on Grafana? or are you using variables from Grafana in that query? .

If the intention was the second one, then I am not seeing any variable being referenced in that query.

---

<div class="post-metadata">

**Author:** ![AVVS\_Sudheer](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/avvs_sudheer/32/13075_2.png) [@AVVS\_Sudheer](https://community.influxdata.com/u/AVVS_Sudheer)\
**Post date:** [May 6, 2023, 4:46am UTC](https://community.influxdata.com/t/variable-not-working/29795/3 "2023-05-06T04:46:49Z")

</div>

Hi,

The above query is used in grafana to get values into variable from influxdb and use it in grafana report

Regards  
Sudheer

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [May 8, 2023, 10:38am UTC](https://community.influxdata.com/t/variable-not-working/29795/4 "2023-05-08T10:38:02Z")

</div>

Hello @AVVS_Sudheer,  
That might be more a question for [https://community.grafana.com/](https://community.grafana.com/) then 🙂

---

<div class="post-metadata">

**Author:** ![AVVS\_Sudheer](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/avvs_sudheer/32/13075_2.png) [@AVVS\_Sudheer](https://community.influxdata.com/u/AVVS_Sudheer)\
**Post date:** [May 9, 2023, 6:27am UTC](https://community.influxdata.com/t/variable-not-working/29795/5 "2023-05-09T06:27:20Z")

</div>

Hi,

Now this query is working fine. I have tried diff methods and at last one method has worked. At first in the new grafana dashboard, we have to set the time range to 1 year and then create a variable.it will work. As in the variable we have start and stop range

Regards  
Sudheer

---

<div class="post-metadata">

**Author:** ![fercasjr](https://avatars.discourse-cdn.com/v4/letter/f/e495f1/32.png) [@fercasjr](https://community.influxdata.com/u/fercasjr)\
**Post date:** [May 9, 2023, 8:53pm UTC](https://community.influxdata.com/t/variable-not-working/29795/6 "2023-05-09T20:53:05Z")

</div>

Oh, I think I know where your confusion is coming from.

when you use |\> range(start: v.timeRangeStart, stop: v.timeRangeStop) as yo do in influxdb’s data explorer.

in Grafana dashboards. it will translate both variables to the time values selected in Grafana time picker:  
 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/3/37534fb67751482eac42201feab1e652767ea041.png)

v.timeRangeStart and v.timeRangeStop are both variables from the time picker in both software

If you need specific time ranges either select the range using the time pickers or hard code the values like you did

---

<div class="post-metadata">

**Author:** ![AVVS\_Sudheer](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/avvs_sudheer/32/13075_2.png) [@AVVS\_Sudheer](https://community.influxdata.com/u/AVVS_Sudheer)\
**Post date:** [May 10, 2023, 5:02am UTC](https://community.influxdata.com/t/variable-not-working/29795/7 "2023-05-10T05:02:29Z")

</div>

Hi,

Thanks for your suggestion. I tried that way by giving the date range. It is working fine now

Regards  
Sudheer
