Adding a Grafana dashboard variable creates a dropdown that swaps a query value without editing each panel. It fits dashboards that need to move between services, regions, hosts, or other repeated labels while keeping one saved layout.

Grafana stores variables with the dashboard and displays visible variables above the panels by default. Query variables fetch their options from a selected data source, while panel queries refer to the variable name with syntax such as $region or ${region}.

A TestData query of * returns lettered values from A through H, which makes a variable easy to verify without external metrics. Use the same editor flow with Prometheus, InfluxDB, or another data source, but replace the variable query with that data source's label, tag, or field lookup.

Steps to add a variable to a Grafana dashboard:

  1. Open the dashboard that should receive the dropdown.
  2. Click Edit in the dashboard toolbar.

    The dashboard needs edit permission. View-only users can change existing variable values but cannot save a new variable.

  3. Click Add variable in the dashboard editor.
  4. Select Query as the variable type.

    Query variables ask a data source for values. Use Custom only when the allowed values are a fixed list.

  5. Enter the variable name.
    region

    Use a short identifier without spaces because panel queries reference the value as $region or ${region}.

  6. Enter the dashboard label.
    Region

    The label is the text shown beside the dropdown. If it is left blank, Grafana shows the variable name.

  7. Select the target data source.
  8. Enter the variable query.
    *

    The TestData data source returns top-level values A through H for *. Other data sources use their own query syntax, such as a label-values query for Prometheus or a tag query for InfluxDB.

  9. Set Sort to Alphabetical (asc).
  10. Set Refresh to On dashboard load.

    Use On time range change only when the variable query depends on the dashboard time range.

  11. Click Preview.
  12. Confirm the expected values appear in Preview of values.
  13. Close the variable editor.
  14. Save the dashboard.
  15. Edit the panel that should use the new variable.
  16. Add the variable to the panel query.
    region=$region

    The screenshot uses the TestData Labels field. In a metric query, place the variable where the data source expects the filter value, such as a label matcher, tag value, or field predicate.

  17. Save the panel.
  18. Save the dashboard.
  19. Open the variable dropdown and select another value.
  20. Confirm the panel refreshes with the selected value.

    If the panel shows No data, check the variable value, dashboard time range, and panel request in Query inspector.
    Related: How to use Grafana query inspector