Grafana Guide: Variables, Filters and Repeats

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Checked on 2026-11-11 against Grafana 13.3.x.

What you build

You add five variables to the dashboard Bookshelf (guides): Application and Route, two chained query variables whose values come from Prometheus, a custom variable Percentile, an interval variable Window and a data source variable ds. You also add a Filter and Group by control. A new time series panel uses the variables in its data source, its query and its title, and Grafana repeats it once for each route you select.

Finished dashboard Bookshelf (guides) in view mode: the variable controls Application, Route, Window, Percentile and ds sit in a row under the toolbar, and the panel Requests per second for $route is repeated once for each of the routes /api/books, /api/loans and /api/search

Before you start

  • Start the Grafana profile of the hands-on lab and wait about a minute:

    cd lab
    docker compose --profile grafana up -d
  • Open http://localhost:3000, sign in as admin with the password admin, and click Skip when Grafana 13.3 asks you to update the default password.

  • Do the earlier guides in this series, at least Create a dashboard and the first panel, which creates the dashboard Bookshelf (guides) in the folder Guides.

  • The data source Prometheus is provisioned by the lab and is the default data source. The load generator runs in its default mode and gives the queries traffic to draw.

  • The guide was checked on Grafana Enterprise 13.3.0 (the free image, no licence key). Editing dashboards needs the Editor or Admin role of the organization; admin has it.

  • The figures are drawings of the Grafana 13.3 user interface, not screenshots, so small details can differ from your screen. A highlighted box with a number marks the control of the step with the same number.

Steps

In Grafana 13.3 the variable settings no longer have a tab of their own: the Variables tab of the dashboard settings only says that they have moved to the dashboard sidebar. The sidebar pane opened by the Options icon lists Filters, Variables, Annotations and Links, each with a plus button, and the old ad hoc filters are the Filter and Group by control of Filters. The edit toolbar, the sidebar and the panel editor are drawn on the screen maps of the guide Create a dashboard and the first panel; come back to them when a control is not where a figure shows it. The forms of the Custom, Interval and Data source variables and the Repeat options are drawn from the names Grafana gives them; if a label differs on your screen, pick the closest entry.

Open the variables pane

  1. In the left navigation, click Dashboards, then open the folder Guides and the dashboard Bookshelf (guides).

  2. Click Edit.

    Dashboard Bookshelf (guides) in view mode with the navigation docked: callout 1 marks the Dashboards item of the navigation and callout 2 marks the Edit button of the toolbar
  3. In the icon strip of the right sidebar, click Options.

  4. In the pane Dashboard, click the plus button next to Variables.

    Dashboard in edit mode with the Options icon of the right sidebar marked by callout 3 and the Dashboard pane open: View all settings, Title, Description, Layout and the lists Filters, Variables, Annotations and Links, each with a plus button; the plus of Variables is marked by callout 4
  5. In the list Choose variable type, click Query ("Values are fetched from a data source query"). The list also offers Switch, a new type for a variable that is toggled on and off.

    The Choose variable type list of the dashboard sidebar with the types Query, Custom, Textbox, Constant, Data source, Interval and Switch; Query, described as values fetched from a data source query, is marked by callout 5

Create the Application and Route query variables

  1. In the form Query variable, type application in Name.

  2. Type Application in Label.

  3. Under Query options, click Open variable editor.

    The Query variable form in the dashboard sidebar: the Name field holds application (callout 6), the Label field holds Application (callout 7), and the Open variable editor button under Query options is marked by callout 8; the Selection options toggles are all off
  4. In the editor, choose the data source Prometheus.

  5. Set up the query so that it returns the values of the label application of the metric http_server_requests_seconds_count. In the definition of the query this reads:

    label_values(http_server_requests_seconds_count, application)
  6. Close the editor.

    The query editor of the variable opened with Open variable editor: the data source Prometheus is selected (callout 9), the query label_values with the metric http_server_requests_seconds_count and the label application is typed in the editor (callout 10), and the close icon of the editor is marked by callout 11
  7. Click the plus button next to Variables again and choose Query.

  8. Type route in Name.

  9. Type Route in Label.

  10. Click Open variable editor.

    The Query variable form for the second variable: the Name field holds route (callout 13), the Label field holds Route (callout 14), and the Open variable editor button is marked by callout 15
  11. Choose Prometheus and set up the query so that it returns the values of the label uri, filtered by the first variable. The query refers to the first variable as $application, which is what chains the two variables:

    label_values(http_server_requests_seconds_count{application="$application"}, uri)
  12. Close the editor.

    The variable query editor with the chained query: label_values of the metric http_server_requests_seconds_count filtered by application equal to $application, for the label uri, typed in the editor (callout 16); the close icon is marked by callout 17
  13. Under Selection options, switch on Multi-value.

  14. Switch on Include All value, so that the control offers All next to the single routes.

    The Query variable form of the variable route scrolled to Selection options: the toggle Multi-value is on (callout 18), Include All value is on (callout 19) and Allow custom values stays off

Add a custom, an interval and a data source variable

  1. Click the plus button next to Variables and choose Custom.

  2. Type percentile in Name.

  3. Type Percentile in Label.

  4. In the list of values, type 0.5,0.9,0.95,0.99.

    A Custom variable form: Name percentile (callout 21), Label Percentile (callout 22) and the list of values 0.5,0.9,0.95,0.99 (callout 23)
  5. Click the plus button next to Variables and choose Interval ("Values are timespans, ex 1m, 1h, 1d").

  6. Type window in Name.

  7. Type Window in Label.

  8. In the list of intervals, type 1m,5m,10m.

    An Interval variable form: Name window (callout 25), Label Window (callout 26) and the list of intervals 1m,5m,10m (callout 27)
  9. Click the plus button next to Variables and choose Data source.

  10. Type ds in Name.

  11. Choose the type Prometheus.

    A Data source variable form: Name ds (callout 29) and the data source type Prometheus (callout 30)

Add a Filter and Group by control

  1. Click the plus button next to Filters.

  2. For the new Filter and Group by entry, choose the data source Prometheus. The control now offers label filters and a group by for the queries of that data source.

    The Dashboard pane with the list Filters open: the plus button of Filters is marked by callout 31 and the new entry for the Filter and Group by control shows the data source Prometheus, marked by callout 32

Use the variables in a panel

  1. Click Add in the toolbar, click the Panel tile in the Add pane and click Edit visualization, as in the first dashboard guide.

  2. Open the data source picker of query A and choose the variable ${ds}, which is listed with the data sources.

  3. Click Code in the Builder / Code switch.

  4. Click inside the query editor first, so that it has the focus, then type the query on one line (the editor may wrap it):

    sum by (status) (rate(http_server_requests_seconds_count{application="$application", uri=~"$route"}[$window]))
  5. Click Run queries.

  6. Under Suggestions, click Time series.

  7. In the options pane, under Panel options, type Requests per second for $route in Title.

    Panel editor of a time series panel titled Requests per second for $route: the data source picker holds the variable ds (callout 34), the query that uses $application, $route and $window is typed in the editor (callout 36), Run queries is marked by callout 37 and the Title field of the options pane holds the same title (callout 39)

Repeat the panel for each route

  1. In the options pane, open the category Repeat options.

  2. Choose the variable route as the variable to repeat by.

    Options pane of the panel with the category Repeat options open: the category header is marked by callout 40 and its variable select holds route, marked by callout 41
  3. Click Save in the header of the editor.

  4. In the Save dashboard drawer, click Save.

  5. Click Back.

  6. Click Exit edit.

  7. If Grafana 13.3.0 shows the dialog Unsaved changes, click Save, and click Save again in the drawer that opens.

Check the result

Open Dashboards → Guides → Bookshelf (guides). The controls Application, Route, Window, Percentile and ds sit above the panels. In Route, select /api/books, /api/loans and /api/search; the panel Requests per second for $route is drawn once for each of them, and the title of every copy names its route. Choosing All draws one copy for each of the four routes of the Bookshelf service. Change Window to 1m and watch the lines get more jagged.

To try the Filter and Group by control, use it at the top of the dashboard to add a filter for the label status with the value 404, and see the lines for the other status codes disappear from the panels that use the data source Prometheus queries.

To see a new series appear in every copy, force errors, wait about a minute and press Refresh:

curl -X POST localhost:8090/mode/failing

Restore normal traffic afterwards:

curl -X POST localhost:8090/mode/normal

Variations

  • Repeat a whole row instead of a panel: in edit mode add a row from the Add pane under Group layouts, move the panel into the row, remove the repeat of the panel and choose the variable route in the repeat options of the row.

  • Use the custom variable in a latency query: put $percentile as the first argument of histogram_quantile and $window as the range of rate, and choose another percentile in the control.

  • Add a Switch variable (the new type of step 5) and use it to turn a part of a query on and off.

What can go wrong

Symptom Cause Fix

The Route control is empty

The second variable asks for the routes of $application, and the first variable has no value yet.

Pick a value in Application and press Refresh, or check that the query of Application returns bookshelf.

The panel is not repeated

The variable of the repeat is not multi-value, or only one route is selected.

Switch on Multi-value and Include All value in the variable route and select several routes or All.

The panel says No data for $window

The interval variable holds a value that is not a duration, such as an empty list entry.

Open the variable window and keep only entries like 1m,5m,10m.

The picker does not list ${ds}

The data source variable was not saved, or its type is not Prometheus.

Open the variable in the sidebar and set the type Prometheus, then open the picker again.

The title of a copy shows $route

The panel is not repeated, so the variable is shown with all its values.

Select the routes in Route and check the repeat options of the panel.

Clean up

Keep the variables and the panel if you want to try the variations. To remove the panel, open the dashboard in edit mode, select it, click Delete in the Panel pane of the right sidebar and save the dashboard. A variable is removed from its form with Delete. The later guides in this series do not depend on them.

Where to go next