# Apply Variables in Dynatrace DQL Filters Using matchesPhrase

**URL:** <https://community.dynatrace.com/t/apply-variables-in-dynatrace-dql-filters-using-matchesphrase/51263>\
**Category:** DQL\
**Tags:** dql, variables, dashboards, logs\
**Created:** [April 16, 2025, 3:25pm UTC](https://community.dynatrace.com/t/apply-variables-in-dynatrace-dql-filters-using-matchesphrase/51263 "2025-04-16T15:25:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pditmar2](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@pditmar2](https://community.dynatrace.com/u/pditmar2)\
**Post date:** [April 16, 2025, 3:25pm UTC](https://community.dynatrace.com/t/apply-variables-in-dynatrace-dql-filters-using-matchesphrase/51263/1 "2025-04-16T15:25:12Z")

</div>

_Summary:_ _Wildcard searches in Dynatrace can be challenging because DQL requires string variables to be enclosed in quotation marks. To work around this, use the `concat` function to add wildcards around the variable. Example DQL:_

```auto
<em>fetch logs
| filter matchesValue(content, concat("*", $requestId, "*")) AND matchesValue(content, "* RequestId=*")</em>

```

I am trying to use a variable in a filter in DQL on my dashboard.

The **$requestId** variable is created as following :

```markup
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

```

The results of the variable query are for example :

09b4597940e040caaa5fd3a2b580145127c9e98b933b42a4b7d27923c52c8235299a6d18441a42b9a0b3a5c6dc22b1a9On my dashboard I try to apply a filter on the **$requestId** as following :

```markup
fetch logs
| filter matchesValue(content, "*$requestId*") AND matchesValue(content, "* RequestId=*")
​

```

Unfortunately I run into the following error :

```markup
"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"
      ],

```

If I remove the $variable and just add one of the results it works fine. The problem seems to be that the \" that are added around the variable.

Is there any way to fix this?

Thanks,

Patrick

---

<div class="post-metadata">

**Author:** ![marco\_irmer](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marco_irmer/32/3038_2.png) [@marco\_irmer](https://community.dynatrace.com/u/marco_irmer)\
**Post date:** [April 16, 2025, 4:57pm UTC](https://community.dynatrace.com/t/apply-variables-in-dynatrace-dql-filters-using-matchesphrase/51263/2 "2025-04-16T16:57:18Z")

</div>

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.

As a workaround, I recommend using the concat function to wrap the variable value in wildcards. The revised DQL will look like this:

```javascript
fetch logs
| filter matchesValue(content, concat("*", $requestId, "*")) AND matchesValue(content, "* RequestId=*")

```

---

<div class="post-metadata">

**Author:** ![pditmar2](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@pditmar2](https://community.dynatrace.com/u/pditmar2)\
**Post date:** [April 16, 2025, 8:42pm UTC](https://community.dynatrace.com/t/apply-variables-in-dynatrace-dql-filters-using-matchesphrase/51263/3 "2025-04-16T20:42:49Z")

</div>

Thanks a lot, that works!
