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
-
In the upper-right of the dashboard, open the
Add menu and select
Add variable.
-
Define the variable.
-
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
- In the upper-left corner of the dashboard, select
to open the Manage variables page.
- In the Name column, select the name of the variable that you want to edit.
- Edit the variable.
- Select Run query and inspect the results in the Preview section to make sure it works as expected.
- Select Save. You can't select Save until you select Run query.
- 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
-
In the upper-left corner of the dashboard, select
.
The Manage variables window lists all variables on your dashboard.
-
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
-
In the upper-left of the dashboard, open a variable menu. In this example, a dashboard named
My animal colors
has two variables,Animal
andColor
, and we are going to open theAnimal
variable's menu.
-
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.
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.
Query variable
To define a query variable
- 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
, orVariable01
.
- Set Type to
Query
. - In Definition, enter a query.
- Select Run query and inspect the results in the Preview section to make sure it works as expected.
- If you want to be able to select more than one value at a time, turn on Multi-select.
- Select Add variable to save your changes and return to the dashboard.
Example query variable 1
- Name: Hosts
- Type: Query
- Definition:
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:
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
- 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
, orVariable01
.
- Set Type to
CSV
. - In Definition, enter a comma-separated list of possible values for this variable, such as
dog, cat, horse
. - Inspect the results in the Preview section to make sure it works as expected.
- If you want to be able to select more than one value at a time, turn on Multi-select.
- 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:
WARN, ERROR, INFO, NONE
- Multi-select: on
Code variable
To define a code variable
- 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
, orVariable01
.
- Set Type to
Code
. - In Definition, enter the JavaScript code.
- Select Run query and inspect the results in the Preview section to make sure it works as expected.
- If you want to be able to select more than one value at a time, turn on Multi-select.
- Select Add variable to save your changes and return to the dashboard.
Example code variable 1
- Name: CodeVariable
- Type: Code
- Definition:
/* * This will run JavaScript in the DYNATRACE * serverless environment. * To generate variable options return string array. */ export default async function () { return ["val1", "val2", "val3"] }