Nested variables let you create dynamic, dependent relationships between variables on your dashboards. This allows you to:
- Reuse dashboard variables and dynamically change what's shown, especially for filtering based on other variables' data.
- Create parent/child relationships in variables, forming a tree structure where you can select different levels of filters.
Use case
Imagine you've created an Env variable to select an environment (for example, production and staging). You want to update a Machine variable with a list of machines based on the selected environment. Directly embedding the Env variable in a WHERE condition for Machine isn't supported in a standard setup.
Important
The nested variables feature is available only to Pro, Enterprise, and Core Compute customers. To learn more about our pricing model, editions, and buying programs, refer to the pricing documentation.
Example:
Variable Env=productionorstagingVariable Machine=SELECT uniques(machine) FROM Table WHERE env IN ({{Env}})
This direct approach isn't supported without nested variables. Nested variables solve this by allowing your Machine variable's query to dynamically reference the value of your Env variable.
How to use nested variables
To implement nested variables, follow these steps:
- Go to a dashboard you can edit.
- Create your parent variable (for example,
env) by using theAdd Variablefunction:FROM TransactionSELECT uniques(environment) - Create another variable (for example,
variable_cluster) and, when defining it, place{{env}}inside the textbox:FROM TableSELECT uniques(machine)WHERE env IN ({{env}}) - Save both variables.
- Go to your dashboard and interact with the variable's values. They should automatically change based on the nested variable value selection.
Now you can use your child variable inside any widget on your dashboard. When your variable_cluster changes, your widget will also change!
Limitations
When you use nested variables, be aware of the following limitations:
- Parent variable selection required for child definition: Make sure your
envvariable has selected values when you define yourmachinevariable. Otherwise, themachinequery will return no results. - Variable selection required for widget usage: Ensure the variable has selected values when you use it inside widgets. Otherwise, the widget's query will return no results.
- Deletion impact: If your
envvariable is deleted, yourmachinevariable may show errors when loading. - Cleared values: If your
envvariable's values are cleared, yourmachinevariable will continue to show values based onenv's previous selections.