# Metrics as Variables

**URL:** <https://community.dynatrace.com/t/metrics-as-variables/51623>\
**Category:** Dashboarding\
**Tags:** dql, dynatrace-managed, variables, latest-dynatrace, dashboards\
**Created:** [May 14, 2025, 6:59am UTC](https://community.dynatrace.com/t/metrics-as-variables/51623 "2025-05-14T06:59:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![VictorRuiz](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/victorruiz/32/32860_2.png) [@VictorRuiz](https://community.dynatrace.com/u/VictorRuiz)\
**Post date:** [May 14, 2025, 6:59am UTC](https://community.dynatrace.com/t/metrics-as-variables/51623/1 "2025-05-14T06:59:21Z")

</div>

Hi all,

I am creating a dashbord for capacity management but I would like the metric to be selectable by a variable.

I currently have several variables created that allow me to filter by host entity tags and variables that allow me to select the metric type (avg, max, min).&nbsp;The problem I am having is when trying to use the variables to select the metric.

I have a variable ($Metric) that contains:

- dt.host.cpu.usage
- dt.host.memory.usage

I want to use that variable in a simple DQL for example:

timeseries usage = percentile(dt.host.cpu.usage, 95, rollup: avg), by:{dt.entity.host}, from: -7d | limit 2

That is:

timeseries usage = percentile( **$Metric** , 95, rollup: avg), by:{dt.entity.host}, from: -7d | limit 2

When doing so I get an error: “The parameter has to be a metric key.” “queryString“: ‘timeseries usage = percentile( **\’dt.host.cpu.usage\”** , 95, rollup: \“avg”), by:{dt.e…

I understand that the problem is how to parse the value of the variable to the query, is there any way to do it?

Thanks a lot for your time

Victor

---

<div class="post-metadata">

**Author:** ![GerardJ](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gerardj/32/154_2.png) [@GerardJ](https://community.dynatrace.com/u/GerardJ)\
**Post date:** [May 14, 2025, 7:46am UTC](https://community.dynatrace.com/t/metrics-as-variables/51623/2 "2025-05-14T07:46:12Z")

</div>

Hi

You should try using the [“:noquote”](https://docs.dynatrace.com/docs/shortlink/dashboard-component-variable#variable-replacement)&nbsp; option for variable replacement like this :

```markup
timeseries usage = percentile($Metric:noquote, 95, rollup: avg), by:{dt.entity.host}, from: -7d | limit 2

```

---

<div class="post-metadata">

**Author:** ![VictorRuiz](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/victorruiz/32/32860_2.png) [@VictorRuiz](https://community.dynatrace.com/u/VictorRuiz)\
**Post date:** [May 14, 2025, 8:26am UTC](https://community.dynatrace.com/t/metrics-as-variables/51623/3 "2025-05-14T08:26:27Z")

</div>

Works 🖖,

Thanks a lot

Victor
