# DQL to filter problem events by alerting profile

**URL:** <https://community.dynatrace.com/t/dql-to-filter-problem-events-by-alerting-profile/43355>\
**Category:** DQL\
**Tags:** dql, notebooks\
**Created:** [December 24, 2023, 1:30am UTC](https://community.dynatrace.com/t/dql-to-filter-problem-events-by-alerting-profile/43355 "2023-12-24T01:30:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dneimke](https://avatars.discourse-cdn.com/v4/letter/d/f17d59/32.png) [@dneimke](https://community.dynatrace.com/u/dneimke)\
**Post date:** [December 24, 2023, 1:30am UTC](https://community.dynatrace.com/t/dql-to-filter-problem-events-by-alerting-profile/43355/1 "2023-12-24T01:30:32Z")

</div>

I have a DQL query that returns a list of events for problem records which looks like this:

```markup
fetch events, from:now()-30d, to:now()  
| filter event.kind == "DAVIS_PROBLEM"
| filter contains(event.name, "database connection")

```

The query returns records as expected, but now I want to modify the query to filter for just a single alerting profile.

I can see the alerting profiles are coming through in a field/property named labels.alerting\_profile

 ![Screenshot 2023-12-24 115728.png](https://global.discourse-cdn.com/dynatrace/original/3X/3/9/3933ead11df725a38323fd74be18bb703dfef8ed.png)

How can I add a filter to my DQL query so that it returns just the alerting\_profile records I want?

---

<div class="post-metadata">

**Author:** ![Yosi\_Neuman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/yosi_neuman/32/9845_2.png) [@Yosi\_Neuman](https://community.dynatrace.com/u/Yosi_Neuman)\
**Post date:** [December 24, 2023, 7:23am UTC](https://community.dynatrace.com/t/dql-to-filter-problem-events-by-alerting-profile/43355/2 "2023-12-24T07:23:53Z")

</div>

Hi&nbsp;[@dneimke](https://community.dynatrace.com/user/52176)

You can try:

```javascript
| filter matchesValue(labels.alerting_profile,"<the AP you are looking for>")

```

HTH

Yos

---

<div class="post-metadata">

**Author:** ![dneimke](https://avatars.discourse-cdn.com/v4/letter/d/f17d59/32.png) [@dneimke](https://community.dynatrace.com/u/dneimke)\
**Post date:** [December 24, 2023, 8:11am UTC](https://community.dynatrace.com/t/dql-to-filter-problem-events-by-alerting-profile/43355/3 "2023-12-24T08:11:58Z")

</div>

Thanks&nbsp;[@Yosi\_Neuman](https://community.dynatrace.com/user/6931), that worked!

As a follow up… do you know if it’s possible to declare and use variables in grail queries? Similar to using [the let statement in kusto queries](https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/letstatement).

For example, something like this psuedo-code:

```csharp
// declare a variable
let p = "my_alerting_profile_name"

fetch events, from:now()-30d, to:now()  
... omitted for brevity
| filter matchesValue(profile, $p) // <-- use the variable here

```

Note: I’m using these queries in a Notebook

---

<div class="post-metadata">

**Author:** ![AntonPineiro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antonpineiro/32/49_2.png) [@AntonPineiro](https://community.dynatrace.com/u/AntonPineiro)\
**Post date:** [December 24, 2023, 12:20pm UTC](https://community.dynatrace.com/t/dql-to-filter-problem-events-by-alerting-profile/43355/4 "2023-12-24T12:20:10Z")

</div>

Hi,

I am not sure but maybe [this works](https://docs.dynatrace.com/docs/shortlink/dashboard-component-variable) for you.

Best regards

---

<div class="post-metadata">

**Author:** ![Yosi\_Neuman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/yosi_neuman/32/9845_2.png) [@Yosi\_Neuman](https://community.dynatrace.com/u/Yosi_Neuman)\
**Post date:** [December 24, 2023, 12:24pm UTC](https://community.dynatrace.com/t/dql-to-filter-problem-events-by-alerting-profile/43355/5 "2023-12-24T12:24:08Z")

</div>

Hi&nbsp;[@dneimke](https://community.dynatrace.com/user/52176)

Ammm found [variables only for dashboards](https://docs.dynatrace.com/docs/shortlink/dashboard-component-variable)&nbsp;:roll\_eyes:

Don’t know how to add variables to notebook 🤔

Yos
