<?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: Using Variable in DQL filter with matchesPhrase in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/Apply-Variables-in-Dynatrace-DQL-Filters-Using-matchesPhrase/m-p/275326#M1948</link>
    <description>&lt;P&gt;It's a bit tricky because you're attempting to do a wildcard search here, whereas Dynatrace insists on enclosing the string variable value in quotations during query executions.&lt;/P&gt;&lt;P&gt;As a workaround, I recommend using the concat function to wrap the variable value in wildcards. The revised DQL will look like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;fetch logs
| filter matchesValue(content, concat("*", $requestId, "*")) AND matchesValue(content, "* RequestId=*")&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 16 Apr 2025 16:57:18 GMT</pubDate>
    <dc:creator>marco_irmer</dc:creator>
    <dc:date>2025-04-16T16:57:18Z</dc:date>
    <item>
      <title>Apply Variables in Dynatrace DQL Filters Using matchesPhrase</title>
      <link>https://community.dynatrace.com/t5/DQL/Apply-Variables-in-Dynatrace-DQL-Filters-Using-matchesPhrase/m-p/275324#M1947</link>
      <description>&lt;P&gt;&lt;EM&gt;Summary:&amp;nbsp;&lt;/EM&gt;&lt;EM style="font-family: inherit;"&gt;Wildcard searches in Dynatrace can be challenging because DQL requires string variables to be enclosed in quotation marks. To work around this, use the &lt;CODE&gt;concat&lt;/CODE&gt; function to add wildcards around the variable. Example DQL:&lt;/EM&gt;&lt;/P&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;EM&gt;&lt;CODE&gt;fetch logs
| filter matchesValue(content, concat("*", $requestId, "*")) AND matchesValue(content, "* RequestId=*")&lt;/CODE&gt;&lt;/EM&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;I am trying to use a variable in a filter in DQL on my dashboard.&lt;/P&gt;
&lt;P&gt;The &lt;STRONG&gt;$requestId&lt;/STRONG&gt; variable is created as following :&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;fetch logs
| filter matchesValue(content, "* RequestId=*")
| parse content, "LD ' RequestId=' [a-zA-Z0-9]*:requestId",
    parsingPrerequisite: contains(content," RequestId=")
//| fields requestId2 = toUid(requestId)
| filterOut requestId == "null"
| summarize distinctrequestId = collectDistinct(requestId)
| expand distinctrequestId
| sort distinctrequestId&lt;/LI-CODE&gt;
&lt;P&gt;The results of the variable query are for example :&lt;/P&gt;
&lt;DIV class=""&gt;
&lt;DIV class=""&gt;09b4597940e040caaa5fd3a2b5801451&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class=""&gt;
&lt;DIV class=""&gt;27c9e98b933b42a4b7d27923c52c8235&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class=""&gt;
&lt;DIV class=""&gt;299a6d18441a42b9a0b3a5c6dc22b1a9&lt;/DIV&gt;
&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class=""&gt;On my dashboard I try to apply a filter on the &lt;STRONG&gt;$requestId&lt;/STRONG&gt; as following :&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;LI-CODE lang="markup"&gt;fetch logs
| filter matchesValue(content, "*$requestId*") AND matchesValue(content, "* RequestId=*")
​&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately I run into the following error :&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;      "errorType": "PARSE_ERROR",
      "errorMessage": "`e9d2e0eb03eb48449fef78e6fe9d7130` isn't allowed here. Please check the autocomplete suggestions before the error for alternative options.",
      "arguments": [
        "`e9d2e0eb03eb48449fef78e6fe9d7130`"
      ],
      "queryString": "fetch logs\n| filter matchesValue(content, \"*\"e9d2e0eb03eb48449fef78e6fe9d7130\"*\") AND matchesValue(content, \"* RequestId=*\")",
      "errorMessageFormatSpecifierTypes": [
        "INPUT_QUERY_PART"
      ],&lt;/LI-CODE&gt;
&lt;P&gt;If I remove the $variable and just add one of the results it works fine. The problem seems to be that the&amp;nbsp;\" that are added around the variable.&lt;/P&gt;
&lt;P&gt;Is there any way to fix this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Patrick&lt;/P&gt;</description>
      <pubDate>Tue, 09 Dec 2025 10:50:37 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Apply-Variables-in-Dynatrace-DQL-Filters-Using-matchesPhrase/m-p/275324#M1947</guid>
      <dc:creator>pditmar2</dc:creator>
      <dc:date>2025-12-09T10:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: Using Variable in DQL filter with matchesPhrase</title>
      <link>https://community.dynatrace.com/t5/DQL/Apply-Variables-in-Dynatrace-DQL-Filters-Using-matchesPhrase/m-p/275326#M1948</link>
      <description>&lt;P&gt;It's a bit tricky because you're attempting to do a wildcard search here, whereas Dynatrace insists on enclosing the string variable value in quotations during query executions.&lt;/P&gt;&lt;P&gt;As a workaround, I recommend using the concat function to wrap the variable value in wildcards. The revised DQL will look like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;fetch logs
| filter matchesValue(content, concat("*", $requestId, "*")) AND matchesValue(content, "* RequestId=*")&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 16 Apr 2025 16:57:18 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Apply-Variables-in-Dynatrace-DQL-Filters-Using-matchesPhrase/m-p/275326#M1948</guid>
      <dc:creator>marco_irmer</dc:creator>
      <dc:date>2025-04-16T16:57:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using Variable in DQL filter with matchesPhrase</title>
      <link>https://community.dynatrace.com/t5/DQL/Apply-Variables-in-Dynatrace-DQL-Filters-Using-matchesPhrase/m-p/275335#M1949</link>
      <description>&lt;P&gt;Thanks a lot, that works!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Apr 2025 20:42:49 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Apply-Variables-in-Dynatrace-DQL-Filters-Using-matchesPhrase/m-p/275335#M1949</guid>
      <dc:creator>pditmar2</dc:creator>
      <dc:date>2025-04-16T20:42:49Z</dc:date>
    </item>
  </channel>
</rss>

