---
title: Work with nested variables
source: https://docs.newrelic.com/docs/query-your-data/explore-query-data/dashboards/nested-variables
---

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 [#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](https://docs.newrelic.com/docs/accounts/accounts-billing/new-relic-one-pricing-billing/new-relic-one-pricing-billing/) documentation.

**Example:**

-   `Variable Env` = `production` or `staging`
-   `Variable 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 [#usage]

To implement nested variables, follow these steps:

1.  Go to a dashboard you can edit.
2.  Create your parent variable (for example, `env`) by using the `Add Variable` function:
    ```sql
    FROM Transaction
    SELECT uniques(environment)
    ```
3.  Create another variable (for example, `variable_cluster`) and, when defining it, place `{{env}}` inside the textbox:
    ```sql
    FROM Table
    SELECT uniques(machine)
    WHERE env IN ({{env}})
    ```
4.  Save both variables.
5.  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 [#limitations]

When you use nested variables, be aware of the following limitations:

-   **Parent variable selection required for child definition:** Make sure your `env` variable has selected values when you define your `machine` variable. Otherwise, the `machine` query 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 `env` variable is deleted, your `machine` variable may show errors when loading.
-   **Cleared values:** If your `env` variable's values are cleared, your `machine` variable will continue to show values based on `env`'s previous selections.

> #### 💡 TIP
>
> To reduce clutter in the variables bar, hide parent or supporting variables that don't require user input. Hidden variables continue to function normally. For more information, see [Show and hide variables](https://docs.newrelic.com/docs/query-your-data/explore-query-data/dashboards/dashboard-template-variables/#variable-visibility).
