Skip to main content

Dashboard Variables

Variables enable you to create interactive, dynamic dashboards that can be filtered and customized without editing. They allow users to change data sources, filter data, and modify queries through dropdown selectors.

What are Variables?

Variables are placeholders that can be used in:
  • Panel queries
  • Panel titles and descriptions
  • Dashboard annotations
  • Dashboard links
  • Alert rule queries

Variable Types

Query Variable

Populate variable values from a data source query:
1

Create Query Variable

Go to Dashboard settingsVariablesNew variable
2

Configure Settings

Set name, label, and type to “Query”
3

Select Data Source

Choose the data source to query
4

Define Query

Write a query that returns variable values
5

Set Refresh Behavior

Choose when the variable updates
6

Save Variable

Click Apply to save the variable
Example Query Variable:

Custom Variable

Define variable values manually:

Datasource Variable

Select from available data sources of a specific type:

Constant Variable

Define a hidden constant value:

Interval Variable

Provide time interval options:

Text Box Variable

Allow free-text input:

Ad Hoc Filters

Create dynamic key-value filters:
Ad hoc filters automatically add filter controls to the dashboard and inject filters into queries.

Using Variables

In Queries

Reference variables using ${variable_name} or $variable_name:

Variable Formats

Format variables for different use cases:

In Titles and Text

Use variables in panel titles and markdown:

Built-in Variables

Grafana provides built-in time and dashboard variables:

Multi-Value Variables

Allow selecting multiple values:

Handling Multi-Value in Queries

Variable Dependencies

Variables can reference other variables:
Variable dependencies create a chain reaction. When a parent variable changes, all dependent variables refresh automatically.

Variable Regex Filtering

Filter and transform variable values using regex:

Regex with Capture Groups

Variable URL Synchronization

Variables sync with URL parameters:

Advanced Configuration

Repeat Panels/Rows by Variable

Create dynamic panels:

Variable Value Groups

Group variable values for better organization:

Best Practices

Naming

Use clear, descriptive variable names: environment not env, server_name not srv

Labels

Provide user-friendly labels that differ from internal variable names

Order

Order variables logically: region → datacenter → server

Defaults

Set sensible default values to avoid empty dashboards

Performance Tips

  • Use VariableRefresh.onDashboardLoad for static data
  • Avoid complex regex patterns on large result sets
  • Limit multi-value selections when possible
  • Use constant variables for frequently used values
  • Cache data source queries when appropriate

Common Patterns

Environment Selector

Dynamic Datasource

Time Interval

Troubleshooting

Variable Not Updating

  • Check refresh setting matches your use case
  • Verify query returns data
  • Check for circular dependencies
  • Review data source permissions

Empty Dropdown

  • Verify query syntax for the data source type
  • Check time range includes data
  • Review regex filter pattern
  • Ensure data source is accessible

Multi-Value Not Working

  • Use appropriate format: ${var:regex} for labels, ${var:singlequote} for SQL
  • Check allValue configuration
  • Verify query supports multiple values

Next Steps

Templating

Learn advanced templating techniques

Creating Dashboards

Apply variables when creating dashboards

Panels

Use variables in panel queries

Sharing

Share dashboards with variable values