# Use "If" based on the variable

**URL:** <https://community.dynatrace.com/t/use-if-based-on-the-variable/47142>\
**Category:** Dashboarding\
**Tags:** dql, dynatrace-managed, notebooks, dashboards\
**Created:** [August 13, 2024, 3:25pm UTC](https://community.dynatrace.com/t/use-if-based-on-the-variable/47142 "2024-08-13T15:25:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wellpplava](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wellpplava](https://community.dynatrace.com/u/wellpplava)\
**Post date:** [August 13, 2024, 3:25pm UTC](https://community.dynatrace.com/t/use-if-based-on-the-variable/47142/1 "2024-08-13T15:25:41Z")

</div>

Hello!

Is it possible to use multiple metrics in Dashboard v3 based on the variable selected in the dashboard?

For example, Store Variable

If == “Store X”  
timeseries max(metric A  
Store Y, metric b…

Basically, we have two architectures, an old one and a new one. We would like to include them in the same dashboard, by changing the variable for a store, the metric will also change.

---

<div class="post-metadata">

**Author:** ![Cameron-Leong](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@Cameron-Leong](https://community.dynatrace.com/u/Cameron-Leong)\
**Post date:** [August 13, 2024, 9:05pm UTC](https://community.dynatrace.com/t/use-if-based-on-the-variable/47142/2 "2024-08-13T21:05:32Z")

</div>

Hello,

You can do this with a very simple code tile. In the example below, CPU usage is used if the variable is “true”, and memory usage is used if the variable is “false”.

```javascript
/*
* This function will run in the Dynatrace JavaScript runtime.
* For more information, visit https://dt-url.net/functions-help
*/
import { queryExecutionClient } from '@dynatrace-sdk/client-query';

export default async function () {
  const timeout = 60;
  let query
  if($Variable == "true"){
      query = 'timeseries avg(dt.host.cpu.usage), by: { host.name } | limit 5';
  }
  else{
    query = 'timeseries avg(dt.host.memory.usage), by: { host.name } | limit 5';
  }

  const response = await queryExecutionClient.queryExecute({ body: { query, requestTimeoutMilliseconds: timeout * 1000, fetchTimeoutSeconds: timeout } });

  return response.result;
}

```

 ![CameronLeong_2-1723583082635.png](https://global.discourse-cdn.com/dynatrace/original/2X/f/f23a05dfd8bd8b4830a853d151711fa1f1b25959.png)

 ![CameronLeong_3-1723583084963.png](https://global.discourse-cdn.com/dynatrace/original/2X/1/10d48a96bb56bb9ce8406016319ab16df00a7d5f.png)
