• Home
  • Observe and explore
  • Dashboards
  • Dashboard tiles and filters
  • Add a variable to a dashboard

Add a variable to a dashboard

Latest Dynatrace

Use variables to filter your dashboards, to act as variable values in code tiles, and as placeholders in tile titles and Markdown tile text.

Add a variable

To add a variable to a dashboard

  1. In the upper-right of the dashboard, open the Add menu and select Add variable.

    Add tile button

  2. Define the variable.

  3. Select Add variable to save your changes.

How you define a variable depends on the Type: Query, CSV, or Code.

List variables

After you add at least one variable to a dashboard, a filter icon is displayed in the upper-left corner of the dashboard.

  • Select to open the Manage variables page, which lists all variables defined for the selected dashboard.
  • If there is no in the upper-left corner of the dashboard, there are no variables defined for the dashboard.

Edit a variable

  1. In the upper-left corner of the dashboard, select to open the Manage variables page.
  2. In the Name column, select the name of the variable that you want to edit.
  3. Edit the variable.
  4. Select Run query and inspect the results in the Preview section to make sure it works as expected.
  5. Select Save. You can't select Save until you select Run query.
  6. Dismiss the Manage variables page.

How you edit a variable depends on the Type: Query, CSV, or Code.

Delete a variable

To delete a variable from a dashboard

  1. In the upper-left corner of the dashboard, select .

    The Manage variables window lists all variables on your dashboard.

  2. Find the filter you want to delete and select in the Delete column.

Change variable values

If a dashboard has one or more variables, they are listed by name along the upper-left of the dashboard, under the dashboard name. When you change variable values, the dashboard contents are recalculated and displayed according to the new values.

To change the value of a variable

  1. In the upper-left of the dashboard, open a variable menu. In this example, a dashboard named My animal colors has two variables, Animal and Color, and we are going to open the Animal variable's menu.

    Dashboard with two variables: Animal and Color

  1. Make your value selection (or selections) for the variable.

    If the variable allows just one selection (value) at a time, select the value that you want to apply to the dashboard.

    Change the value of a single-value variable

    If the variable allows multiple selections (values) at a time, select the checkbox for each value you want to apply to the dashboard.

    • The menu name for that variable will show the value of the variable if only one is selected, but it will instead show the number of values selected if you select more than one value.
    • At least one value has to be selected. In the example below, you would not be able to clear green unless you first selected one or more other values available for that variable.
      • Before you select a second variable value:

        Select additional value for a multi-value variable: before

      • After you select a second variable value:

        Select additional value for a multi-value variable: after

Query variable

To define a query variable

  1. Set Name the name you want to give your variable.
    • It will be displayed at the top of the dashboard, listed on the Manage variables page, and referred to in code.
    • It can contain only letters (uppercase or lowercase) and numbers, such as status, myHosts, or Variable01.
  2. Set Type to Query.
  3. In Definition, enter a query.
  4. Select Run query and inspect the results in the Preview section to make sure it works as expected.
  5. If you want to be able to select more than one value at a time, turn on Multi-select.
  6. Select Add variable to save your changes and return to the dashboard.

Example query variable 1

  • Name: Hosts
  • Type: Query
  • Definition:
    dql
    fetch logs | summarize count(), by:`dt.entity.host` | limit 100 | sort `count()`, direction:"descending" | fields `dt.entity.host`

Example query variable 2

  • Name: Loglevel
  • Type: Query
  • Definition:
    dql
    fetch logs, from:now() - 2h | summarize count(), by:loglevel | sort `count()`, direction:"descending" | fields loglevel

If you add both examples above to your dashboard, you can filter your dashboard by host and log severity level.

  • Be sure to turn on Multi-select if you want to select more than one at a time.

CSV variable

To define a CSV (comma-separated values) variable

  1. Set Name to the name you want to give your variable.
    • Name is displayed at the top of the dashboard, listed on the Manage variables page, and referred to in code.
    • Name can contain only letters (uppercase or lowercase) and numbers, such as status, myHosts, or Variable01.
  2. Set Type to CSV.
  3. In Definition, enter a comma-separated list of possible values for this variable, such as dog, cat, horse.
  4. Inspect the results in the Preview section to make sure it works as expected.
  5. If you want to be able to select more than one value at a time, turn on Multi-select.
  6. Select Add variable to save your changes and return to the dashboard.

Example CSV variable 1

This example would add a $Status variable to your dashboard with the ability to select more than one status at a time, and with four possible values: WARN, ERROR, INFO, NONE.

  • Name: Status
  • Type: CSV
  • Definition:
    plaintext
    WARN, ERROR, INFO, NONE
  • Multi-select: on

Code variable

To define a code variable

  1. Set Name the name you want to give your variable.
    • It will be displayed at the top of the dashboard, listed on the Manage variables page, and referred to in code.
    • It can contain only letters (uppercase or lowercase) and numbers, such as status, myHosts, or Variable01.
  2. Set Type to Code.
  3. In Definition, enter the JavaScript code.
  4. Select Run query and inspect the results in the Preview section to make sure it works as expected.
  5. If you want to be able to select more than one value at a time, turn on Multi-select.
  6. Select Add variable to save your changes and return to the dashboard.

Example code variable 1

  • Name: CodeVariable
  • Type: Code
  • Definition:
    javascript
    /* * This will run JavaScript in the DYNATRACE * serverless environment. * To generate variable options return string array. */ export default async function () { return ["val1", "val2", "val3"] }