You can create a new variable in the Data Explorer, in the Settings or import from InfluxDB in JSON. Here we review the steps to create a variable in the Data Explorer

Dashboard variable types

There are three types of dashboard variables. The types refert to the structuring of the variable's possible values.

  • Map: stores values as key/value pairs in a comma separated format. The UI presents the keys but works with the values.
  • Query: uses values from a Flux query's _value column. (If the values are in another colum, you can first rename that column to _value)
  • CSV: uses a CSV-formatted list.

Create variable in Data Explorer

  1. Open the Data Explorer
  2. Build a query with the Query Builder or the Script Editor
  3. Select Save As at the top right corner
  4. Select the Variable tab.
  5. Add a name for the variable and click Save as Variable

Viewing dashboard variables

You can view variables which belong to your organization.

You can review them in two places:

  1. In the Settings menu on the Variables tab
  2. In the Data Explorer, in Script Editor mode under the Variables tab.

Update, export, or delete a dashboard variable

  1. Open the Settings menu in the navigation bar
  2. Select the Variables tab.
  3. For update, click on a variable's name in the list. To rename, export, or delete, select the appropriate icon in the top right corner of their card.

Variable queries

List buckets

// List buckets in the current organization
buckets()

// Rename the `name` column to `_value`
  |> rename(columns: {"name": "_value"})

// Return a table only with the specific columns
  |> keep(columns: ["_value"])

List measurements

// List all measurements in the bucket

// Import the schema package
import "influxdata/influxdb/schema"

// List the measurements of the specified bucket
schema.measurements(bucket: "bucket-name")

List fields in a measurement

List field in the specified bucket + measurement.

// Import the schema package
import "influxdata/influxdb/schema"

schema.measurementTagValues(
  bucket: "bucket-name",
  measurement: "measurement-name",
  tag: "_field"
)

List unique tag values

List the unique values of the host tag.

import "influxdata/influxdb/schema"

schame.measurementTagValues(bucket: "bucket-name", tag: "host")