InfluxDB can measurement be a variable?

Hello , just asking whether is it possible for measurement to be a variable. if so is there a code that can do so? Thanks

Hi @KaiJ17,
Welcome to the community :slight_smile: . I assume you mean a dashboard varible? In that case yes you can. Simply create a new variable with the following query:

import "influxdata/influxdb/schema"
schema.measurements(bucket: v.bucket)

In this example, you would also have to create a variable called v.bucket as well.

buckets()
  |> filter(fn: (r) => r.name !~ /^_/)
  |> rename(columns: {name: "_value"})
  |> keep(columns: ["_value"])

This would give you ultimate flexibility when using both within any dashboard. If you only have one bucket tough you can also just replace v.bucket with your actual bucket name.

@Jay_Clifford Thanks for welcoming me into the community and also thank you for the response. I have yet to test it but thank you overall for the help!

1 Like

@Jay_Clifford, Hello!

I am here asking how i make the variables appear even though I have followed your steps, i still don’t see my variables on influx DB, i am using influx DB V2.x. These are the following i have tried, i have already created two variables, one is this

import "influxdata/influxdb/schema"
schema.measurements(bucket: v.bucket)

and the other is this

buckets()
|> filter(fn: (r) => r.name !~ /^_/)
|> rename(columns: {name: “_value”})
|> keep(columns: ["_value"])

I hope you can help me on this thanks!



Hi @KaiJ17,
So within your dashboard Flux, you have to make use of the variable like so:

from(bucket: v.bucket)
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "genData")
  |> filter(fn: (r) => r["_field"] == "lon" or r["_field"] == "lat" or r["_field"] == "fuel")
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> rename(columns: {fuel: "_value"})

You can see the v.### are your variable names :slight_smile:

Hello @Jay_Clifford ,

Thank you for the solution it works , i have another question now , which is can your threshold check and deadman check be a variable in influxdb , im using Influxdb V2.x

Thank youu