<?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: Apply variable values in filter with entitySelector in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/272285#M1797</link>
    <description>&lt;P&gt;Try adding timeframe and interval in the by. You are missing that information when you do the summarize:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;timeseries cpu=avg(dt.host.cpu.usage), by:{dt.entity.host}
| lookup [fetch dt.entity.host], sourceField:dt.entity.host, lookupField:id, fields:{tags}
| filter isNotNull(tags)
| expand tags
| parse tags, """((LD:tag (!&amp;lt;&amp;lt;'\\' ':') LD:value)|LD:tag)"""
| fieldsAdd tag = replaceString(tag,"""\:""", ":"), value = replaceString(value, """\:""", ":")
| fieldsAdd client = if(tag == "client", value)
| fieldsAdd environment_type = if(tag == "environment_type", value)
| fieldsAdd function = if(tag == "function", value)
| summarize {cpu = takeAny(cpu), 
  client=arrayMin(collectArray(client)),
  environment_type = arrayMin(collectArray(environment_type)),
  function = arrayMin(collectArray(function))}
  , by:{dt.entity.host, timeframe, interval}
| filter in(client, array($Client)) and 
  in(environment_type, array($Environment))&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 12 Mar 2025 15:51:21 GMT</pubDate>
    <dc:creator>elenaperez</dc:creator>
    <dc:date>2025-03-12T15:51:21Z</dc:date>
    <item>
      <title>Apply variable values in filter with entitySelector</title>
      <link>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/218107#M139</link>
      <description>&lt;P&gt;I have the following query on a dashboard:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;timeseries cpu=avg(dt.host.cpu.usage), filter:in(dt.entity.host,entitySelector("type(host),tag(Environment:DEV)")),by:dt.entity.host&lt;BR /&gt;| sort arrayAvg(cpu), direction:"descending"&lt;BR /&gt;| limit 20&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I have a variable called Environment with the values DEV, SANDBOX and PROD. I wold like to filter the tile based on the variable but substituting DEV by $Environment doesn't work.&lt;/P&gt;
&lt;P&gt;Any idea on how could I create the query?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 15:26:48 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/218107#M139</guid>
      <dc:creator>elenaperez</dc:creator>
      <dc:date>2023-07-14T15:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: Apply variable values in filter with entitySelector</title>
      <link>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/218190#M140</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/58054"&gt;@elenaperez&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you might have noticed from the info message in your environment, the entitySelector will be soon depreciated for usage in DQL. Instead you can use just plain DQL. I guess this example should work for you&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;timeseries cpu=avg(dt.host.cpu.usage), by:{dt.entity.host}
| lookup [fetch dt.entity.host], sourceField:dt.entity.host, lookupField:id, fields:{tags}
| expand tags
| parse tags, """((LD:tag (!&amp;lt;&amp;lt;'\\' ':') LD:value)|LD:tag)"""
| fieldsAdd tag = replaceString(tag,"""\:""", ":"), value = replaceString(value, """\:""", ":")
| filter toString(tag) == "Environment" and toString(value) == $environment
| sort arrayAvg(cpu), direction:"descending"
| limit 20&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;BR /&gt;Sini&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 07:39:52 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/218190#M140</guid>
      <dc:creator>sinisa_zubic</dc:creator>
      <dc:date>2023-07-17T07:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: Apply variable values in filter with entitySelector</title>
      <link>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/218519#M144</link>
      <description>&lt;P&gt;What if I also have another tag called Business_Application that works the same way as Environment and I want to filter on the 2 values? I tried this but it doesn't work (doesn't show any data but it should)&lt;BR /&gt;&lt;BR /&gt;| filter (toString(tag) == "Business Application" and in(toString(value), array($Business_Application))) and (toString(tag) == "Environment" and in(toString(value), array($Environment)))&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2023 10:36:33 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/218519#M144</guid>
      <dc:creator>elenaperez</dc:creator>
      <dc:date>2023-07-19T10:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Apply variable values in filter with entitySelector</title>
      <link>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/218531#M146</link>
      <description>&lt;P&gt;because for every tag you have now one record. This is caused by the &lt;A href="https://www.dynatrace.com/support/help/shortlink/dql-commands#expand" target="_self"&gt;expand command&lt;/A&gt;.&lt;BR /&gt;&lt;BR /&gt;So you need to summarize again the data end extract the tags on which you want to filter. Something like this&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;timeseries cpu=avg(dt.host.cpu.usage), by:{dt.entity.host}
| lookup [fetch dt.entity.host], sourceField:dt.entity.host, lookupField:id, fields:{tags}
| filter isNotNull(tags)
| expand tags
| parse tags, """((LD:tag (!&amp;lt;&amp;lt;'\\' ':') LD:value)|LD:tag)"""
| fieldsAdd tag = replaceString(tag,"""\:""", ":"), value = replaceString(value, """\:""", ":")
| fieldsAdd businessApp = if(tag == "Business Application", value)
| fieldsAdd environment = if(tag == "Environment", value)
| summarize {cpu = takeAny(cpu), 
  businessApp=arrayMin(collectArray(businessApp)),
  environment = arrayMin(collectArray(environment))}
  , by:{dt.entity.host}
| filter in(businessApp, array($Business_Application)) and 
  in(environment, arary($Environment))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;BR /&gt;Sini&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2023 11:12:48 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/218531#M146</guid>
      <dc:creator>sinisa_zubic</dc:creator>
      <dc:date>2023-07-19T11:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: Apply variable values in filter with entitySelector</title>
      <link>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/272281#M1796</link>
      <description>&lt;P&gt;I'm doing this same thing and am having issues with displaying as a time series on a dashboard.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;timeseries cpu=avg(dt.host.cpu.usage), by:{dt.entity.host}
| lookup [fetch dt.entity.host], sourceField:dt.entity.host, lookupField:id, fields:{tags}
| filter isNotNull(tags)
| expand tags
| parse tags, """((LD:tag (!&amp;lt;&amp;lt;'\\' ':') LD:value)|LD:tag)"""
| fieldsAdd tag = replaceString(tag,"""\:""", ":"), value = replaceString(value, """\:""", ":")
| fieldsAdd client = if(tag == "client", value)
| fieldsAdd environment_type = if(tag == "environment_type", value)
| fieldsAdd function = if(tag == "function", value)
| summarize {cpu = takeAny(cpu), 
  client=arrayMin(collectArray(client)),
  environment_type = arrayMin(collectArray(environment_type)),
  function = arrayMin(collectArray(function))}
  , by:{dt.entity.host}
| filter in(client, array($Client)) and 
  in(environment_type, array($Environment))&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;The data set comes out like this (with the tag values not shown):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dmezynski_0-1741792797748.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/26917i6A98CFBF8E9717DB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dmezynski_0-1741792797748.png" alt="dmezynski_0-1741792797748.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The dashboard is telling my the data is not suitable for a graph:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dmezynski_1-1741792898506.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/26918i73E757685D329826/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dmezynski_1-1741792898506.png" alt="dmezynski_1-1741792898506.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2025 15:21:53 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/272281#M1796</guid>
      <dc:creator>dmezynski</dc:creator>
      <dc:date>2025-03-12T15:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Apply variable values in filter with entitySelector</title>
      <link>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/272285#M1797</link>
      <description>&lt;P&gt;Try adding timeframe and interval in the by. You are missing that information when you do the summarize:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;timeseries cpu=avg(dt.host.cpu.usage), by:{dt.entity.host}
| lookup [fetch dt.entity.host], sourceField:dt.entity.host, lookupField:id, fields:{tags}
| filter isNotNull(tags)
| expand tags
| parse tags, """((LD:tag (!&amp;lt;&amp;lt;'\\' ':') LD:value)|LD:tag)"""
| fieldsAdd tag = replaceString(tag,"""\:""", ":"), value = replaceString(value, """\:""", ":")
| fieldsAdd client = if(tag == "client", value)
| fieldsAdd environment_type = if(tag == "environment_type", value)
| fieldsAdd function = if(tag == "function", value)
| summarize {cpu = takeAny(cpu), 
  client=arrayMin(collectArray(client)),
  environment_type = arrayMin(collectArray(environment_type)),
  function = arrayMin(collectArray(function))}
  , by:{dt.entity.host, timeframe, interval}
| filter in(client, array($Client)) and 
  in(environment_type, array($Environment))&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 12 Mar 2025 15:51:21 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/272285#M1797</guid>
      <dc:creator>elenaperez</dc:creator>
      <dc:date>2025-03-12T15:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: Apply variable values in filter with entitySelector</title>
      <link>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/272307#M1798</link>
      <description>&lt;P&gt;Thank you very much!!!! I am just getting into gen3 and DQL. Do you know what modification would be needed to report by entity name instead of the id?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2025 20:09:26 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/272307#M1798</guid>
      <dc:creator>dmezynski</dc:creator>
      <dc:date>2025-03-12T20:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: Apply variable values in filter with entitySelector</title>
      <link>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/272309#M1799</link>
      <description>&lt;P&gt;Got it.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;timeseries cpu=avg(dt.host.cpu.usage), by:{dt.entity.host}
| lookup [fetch dt.entity.host], sourceField:dt.entity.host, lookupField:id, fields:{tags, entity.name}
| filter isNotNull(tags)| expand tags
| parse tags, """((LD:tag (!&amp;lt;&amp;lt;'\\' ':') LD:value)|LD:tag)"""
| fieldsAdd tag = replaceString(tag,"""\:""", ":"), value = replaceString(value, """\:""", ":")
| fieldsAdd client = if(tag == "client", value)
| fieldsAdd environment_type = if(tag == "environment_type", value)
| fieldsAdd function = if(tag == "server_function", value)
| summarize {cpu = takeAny(cpu), 
  client=arrayMin(collectArray(client)),
  environment_type = arrayMin(collectArray(environment_type)),
  function = arrayMin(collectArray(function))}
  , by:{entity.name, timeframe, interval}
| filter in(client, array($Client)) and 
  in(environment_type, array($Environment))
| fieldsRemove client
|fieldsREmove environment_type
|fieldsRemove function&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 12 Mar 2025 20:28:56 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/272309#M1799</guid>
      <dc:creator>dmezynski</dc:creator>
      <dc:date>2025-03-12T20:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: Apply variable values in filter with entitySelector</title>
      <link>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/273743#M1869</link>
      <description>&lt;P&gt;I want to revisit the original question because filtering in the timeseries query is faster than filtering after the query. In order to use a variable as part of an entity selector filter in a timeseries query, you need to use classicEntitySelector, concat and toString.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;timeseries cpu=avg(dt.host.cpu.usage),
  filter:in(dt.entity.host,
            classicEntitySelector(concat("type(host),tag(Environment:",
                                          toString($Environment),
                                          ")")
                                 )
           ),
  by:{dt.entity.host}
| sort arrayAvg(cpu) desc
| limit 20&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;Breaking down the filter, there's an embedded concat in the classicEntitySelector call with three arguments. &amp;nbsp;The first argument is the beginning of the entity selector in quotes. &amp;nbsp;The second argument is the variable converted to a string. &amp;nbsp;The last argument is a quoted close&amp;nbsp;&lt;/SPAN&gt;parentheses to end the entity selector.&lt;BR /&gt;&lt;BR /&gt;Anything you can to do reduce the amount of data returned in the timeseries query will make tiles in dashboards load faster.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 18:40:30 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/273743#M1869</guid>
      <dc:creator>mgome</dc:creator>
      <dc:date>2025-03-27T18:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: Apply variable values in filter with entitySelector</title>
      <link>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/273776#M1872</link>
      <description>&lt;P&gt;That makes sense! Thank you as well&lt;/P&gt;</description>
      <pubDate>Fri, 28 Mar 2025 08:12:53 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/273776#M1872</guid>
      <dc:creator>elenaperez</dc:creator>
      <dc:date>2025-03-28T08:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: Apply variable values in filter with entitySelector</title>
      <link>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/273868#M1874</link>
      <description>&lt;P&gt;We flipped our methodology on this recently.&lt;BR /&gt;We created a hidden variable ($app_servers) to create a list of hosts:&lt;BR /&gt;Note: that hidden variable needs to be multiselect and default to *&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fetch dt.entity.host
|fieldsAdd tags
|filter in(concat("client:",$Client),tags) and in(concat("environment_type:",$Environment),tags)
|fields id&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Then our tiles became much simpler by providing a host list.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;timeseries cpu=avg(dt.host.cpu.usage), by:{dt.entity.host}
|filter in({$app_servers}, dt.entity.host)
|fieldsadd hostname=entityName(dt.entity.host)&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Mar 2025 13:27:39 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Apply-variable-values-in-filter-with-entitySelector/m-p/273868#M1874</guid>
      <dc:creator>dmezynski</dc:creator>
      <dc:date>2025-03-28T13:27:39Z</dc:date>
    </item>
  </channel>
</rss>

