<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Use &amp;quot;If&amp;quot; based on the variable in Dashboarding</title>
    <link>https://community.dynatrace.com/t5/Dashboarding/Use-quot-If-quot-based-on-the-variable/m-p/253340#M4190</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;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".&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;/*
* 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;
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CameronLeong_2-1723583082635.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/21757i07BF7CFE5D58BD06/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CameronLeong_2-1723583082635.png" alt="CameronLeong_2-1723583082635.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CameronLeong_3-1723583084963.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/21758i72E03F6A09CE75FF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CameronLeong_3-1723583084963.png" alt="CameronLeong_3-1723583084963.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Aug 2024 21:05:32 GMT</pubDate>
    <dc:creator>Cameron-Leong</dc:creator>
    <dc:date>2024-08-13T21:05:32Z</dc:date>
    <item>
      <title>Use "If" based on the variable</title>
      <link>https://community.dynatrace.com/t5/Dashboarding/Use-quot-If-quot-based-on-the-variable/m-p/253318#M4188</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;Is it possible to use multiple metrics in Dashboard v3 based on the variable selected in the dashboard?&lt;/P&gt;&lt;P&gt;For example, Store Variable&lt;/P&gt;&lt;P&gt;If == "Store X"&lt;BR /&gt;timeseries max(metric A&lt;BR /&gt;Store Y, metric b....&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 15:25:41 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dashboarding/Use-quot-If-quot-based-on-the-variable/m-p/253318#M4188</guid>
      <dc:creator>wellpplava</dc:creator>
      <dc:date>2024-08-13T15:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Use "If" based on the variable</title>
      <link>https://community.dynatrace.com/t5/Dashboarding/Use-quot-If-quot-based-on-the-variable/m-p/253340#M4190</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;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".&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;/*
* 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;
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CameronLeong_2-1723583082635.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/21757i07BF7CFE5D58BD06/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CameronLeong_2-1723583082635.png" alt="CameronLeong_2-1723583082635.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CameronLeong_3-1723583084963.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/21758i72E03F6A09CE75FF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CameronLeong_3-1723583084963.png" alt="CameronLeong_3-1723583084963.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 21:05:32 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dashboarding/Use-quot-If-quot-based-on-the-variable/m-p/253340#M4190</guid>
      <dc:creator>Cameron-Leong</dc:creator>
      <dc:date>2024-08-13T21:05:32Z</dc:date>
    </item>
  </channel>
</rss>

