Macros
Macros are utility functions that dynamically transform values in your queries. Use them to build dynamic URLs, filter data based on dashboard time ranges, or combine template variable values.
Where to use macros
You can use macros in the following query fields:
- URL
- Request body
- GraphQL query
- URL parameters
- Inline data
- UQL expressions
- GROQ expressions
- Computed column selectors
- Filter expressions
Available macros
Custom interval macro
The $__customInterval() macro returns different values based on the dashboard time range. Use it to adjust query granularity or parameters based on how much time the user is viewing.
Syntax:
$__customInterval(duration1,value1,duration2,value2,...,defaultValue)The macro evaluates conditions in order:
- If dashboard time range ≤
duration1, returnvalue1 - Else if dashboard time range ≤
duration2, returnvalue2 - Continue for additional duration/value pairs
- If no condition matches, return
defaultValue
Duration values must use valid syntax: 1m, 1h, 1d, 7d, etc.
The number of arguments must be odd (3, 5, 7, 9, …).
Example:
$__customInterval(5m,foo,1d,bar,10d,baz,fuzz)If the dashboard time range is 3 hours, the result is bar (because 3h > 5m but ≤ 1d).
More examples:
Combine values macro
The $__combineValues() macro combines multiple values with a prefix, suffix, and separator. This is especially useful with multi-value template variables.
Syntax:
$__combineValues(prefix,suffix,separator,value1,value2,value3,...)Each value gets wrapped with the prefix and suffix, then all results are joined with the separator.
Example:
$__combineValues(key=,, OR ,value1,value2,value3)Result: key=value1 OR key=value2 OR key=value3
Escape sequences
Use escape sequences for special characters in prefix, suffix, or separator:
Basic examples
Note
When the macro receives exactly 4 arguments and the fourth argument is
*, it returns an empty string. This behavior supports the “All” option in multi-value variables.
Use with multi-value variables
This macro works well with multi-value template variables. Configure your variable with:
- Multi-value: Enabled
- Custom all value:
*
Time macros
The ${__timeFrom} and ${__timeTo} macros return the dashboard time range boundaries. These macros are interpolated in the backend, making them suitable for API calls that require time parameters.
Note
Time macros are available from plugin version 2.7.1.
Format options
Given a dashboard start time of 2020-07-13T20:19:09.254Z:
The same format options apply to ${__timeTo}.
Why use Infinity time macros
Use ${__timeFrom} and ${__timeTo} instead of Grafana’s built-in ${__from} and ${__to} variables when making API calls. The Infinity macros are interpolated on the backend, ensuring the time values are correctly passed to external APIs. Grafana’s built-in time variables are interpolated on the frontend, which can cause issues with backend data source requests.
For more information about Grafana’s built-in time variables, refer to Global variables.
Grafana metadata macros
The Infinity data source also supports metadata macros that inject information about the current Grafana context. These are useful for passing user or data source information to APIs.
Note
User macros like
${__user.login}are not available in contexts without a user session, such as alerts, recorded queries, and public dashboards.
For more information about URL configuration and allowed hosts, refer to URL configuration.



