Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/grafana-cloud/connect-externally-hosted/data-sources/azure-monitor/template-variables.md, or by sending Accept: text/markdown to https://grafana.com/docs/grafana-cloud/connect-externally-hosted/data-sources/azure-monitor/template-variables/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
Azure Monitor template variables
Instead of hard-coding details such as resource group or resource name values in metric queries, you can use variables. This helps you create more interactive, dynamic, and reusable dashboards. Grafana refers to such variables as template variables.
For an introduction to templating and template variables, refer to the Templating and Add and manage variables.
Before you begin
- Ensure you have configured the Azure Monitor data source.
- If you want template variables to auto-populate subscriptions, set a Default Subscription in the data source configuration.
Create a template variable
To create a template variable for Azure Monitor:
- Navigate to the dashboard you want to update and click Edit.
- Click the Add new element icon (blue plus sign).
- Click Variable.
- Select Query as the variable type.
- Enter a Name for your variable (e.g.,
subscription,resourceGroup,resource). - Select an option in the Display drop-down list to control where on the dashboard the variable is displayed.
- Click Open variable editor to open the Query Variable dialog box.
- In the Data source drop-down list, select your Azure Monitor data source.
- In the Query Type drop-down list, select the appropriate query type (see Available query types).
- Configure any additional fields required by the selected query type.
- Click Preview to preview the variable values.
- Click Close to close the query variable editor dialog box.
- Configure display options such as Multi-value, Include All value, or Allow custom values as needed.
- Click Save.
- (Optional) Enter a description of the changes you’ve made.
- Click Save.
- Click Exit edit.
Available query types
The Azure Monitor data source provides the following query types for template variables:
| Query type | Description |
|---|---|
| Subscriptions | Returns a list of Azure subscriptions accessible to the configured credentials. |
| Resource Groups | Returns resource groups for a specified subscription. Supports multi-value selection. |
| Namespaces | Returns metric namespaces for the specified subscription. If a resource group is specified, returns only namespaces within that group. |
| Regions | Returns Azure regions available for the specified subscription. |
| Resource Names | Returns resource names for a specified subscription, resource group, and namespace. Supports multi-value selection. |
| Metric Names | Returns available metric names for a specified resource. |
| Workspaces | Returns Log Analytics workspaces for the specified subscription. |
| Logs | Executes a KQL query and returns the results as variable values. Refer to Create a Logs variable. |
| Custom Namespaces | Returns custom metric namespaces for a specified resource. |
| Custom Metric Names | Returns custom metric names for a specified resource. |
Note
Custom metrics cannot be emitted against a subscription or resource group. Select specific resources when retrieving custom metric namespaces or custom metric names.
Create cascading variables
Cascading variables (also called dependent or chained variables) allow you to create dropdown menus that filter based on previous selections. This is useful for drilling down from subscription to resource group to specific resource.
Example: Subscription → Resource Group → Resource Name
Step 1: Create a Subscription variable
- Create a variable named
subscription. - Set Query Type to Subscriptions.
Step 2: Create a Resource Group variable
- Create a variable named
resourceGroup. - Set Query Type to Resource Groups.
- In the Subscription field, select
$subscription.
Step 3: Create a Resource Name variable
- Create a variable named
resource. - Set Query Type to Resource Names.
- In the Subscription field, select
$subscription. - In the Resource Group field, select
$resourceGroup. - Select the appropriate Namespace for your resources (for example,
Microsoft.Compute/virtualMachines).
Now when you change the subscription, the resource group dropdown updates automatically, and when you change the resource group, the resource name dropdown updates.
Create a Logs variable
The Logs query type lets you use a KQL query to populate variable values. The query must return a single column of values.
To create a Logs variable:
- Create a new variable with Query Type set to Logs.
- Select a Resource (Log Analytics workspace or Application Insights resource).
- Enter a KQL query that returns a single column.
Logs variable query examples
| Query | Returns |
|---|---|
Heartbeat | distinct Computer | List of virtual machine names |
Perf | distinct ObjectName | List of performance object names |
AzureActivity | distinct ResourceGroup | List of resource groups with activity |
AppRequests | distinct Name | List of application request names |
You can reference other variables in your Logs query:
workspace("$workspace").Heartbeat | distinct Computerworkspace("$workspace").Perf
| where ObjectName == "$object"
| distinct CounterNameVariable refresh options
Control when your variables refresh by setting the Refresh option:
| Option | Behavior |
|---|---|
| On dashboard load | Variables refresh each time the dashboard loads. Best for data that changes infrequently. |
| On time range change | Variables refresh when the dashboard time range changes. Use for time-sensitive queries. |
For dashboards with many variables or complex queries, use On dashboard load to improve performance.
Use variables in queries
After you create template variables, you can use them in your Azure Monitor queries by referencing them with the $ prefix.
Metrics query example
In a Metrics query, select your variables in the resource picker fields:
- Subscription:
$subscription - Resource Group:
$resourceGroup - Resource Name:
$resource
Logs query example
Reference variables directly in your KQL queries:
Perf
| where ObjectName == "$object" and CounterName == "$metric"
| where TimeGenerated >= $__timeFrom() and TimeGenerated <= $__timeTo()
| where $__contains(Computer, $computer)
| summarize avg(CounterValue) by bin(TimeGenerated, $__interval), Computer
| order by TimeGenerated ascMulti-value variables
You can enable Multi-value selection for Resource Groups and Resource Names variables. When using multi-value variables in a Metrics query, all selected resources must:
- Belong to the same subscription
- Be in the same Azure region
- Be of the same resource type (namespace)
Note
When a multi-value variable is used as a parameter in another variable query (for example, to retrieve metric names), only the first selected value is used. Ensure the first resource group and resource name combination is valid.
Troubleshoot template variables
If you encounter issues with template variables, try the following solutions. For additional troubleshooting, refer to the Azure Monitor troubleshooting guide.
Variable returns no values
- Verify the Azure Monitor data source is configured correctly and can connect to Azure.
- Check that the credentials have appropriate permissions to list the requested resources.
- For cascading variables, ensure parent variables have valid selections.
Variable values are outdated
- Check the Refresh setting and adjust if needed.
- Click the refresh icon next to the variable dropdown to manually refresh.
Variables break after a Grafana upgrade
If template variables return errors such as Properties found in series but missing valueProp and textProp after upgrading Grafana, this typically indicates a version-specific bug. Update to the latest patch release for your Grafana version. For Grafana Cloud, verify you’re on the stable release channel. Refer to
Template variable errors for detailed solutions.
Multi-value selection not working in queries
- Ensure the resources meet the requirements (same subscription, region, and type).
- For Logs queries, use the
$__contains()macro to handle multi-value variables properly.
Was this page helpful?
Related resources from Grafana Labs


