# DQL for Anomaly Detector to compare multiple metrics and trigger alert

**URL:** <https://community.dynatrace.com/t/dql-for-anomaly-detector-to-compare-multiple-metrics-and-trigger-alert/51851>\
**Category:** DQL\
**Tags:** dql, dynatrace-managed, anomaly-detection\
**Created:** [May 28, 2025, 2:38am UTC](https://community.dynatrace.com/t/dql-for-anomaly-detector-to-compare-multiple-metrics-and-trigger-alert/51851 "2025-05-28T02:38:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![p\_devulapalli](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/p_devulapalli/32/41590_2.png) [@p\_devulapalli](https://community.dynatrace.com/u/p_devulapalli)\
**Post date:** [May 28, 2025, 2:38am UTC](https://community.dynatrace.com/t/dql-for-anomaly-detector-to-compare-multiple-metrics-and-trigger-alert/51851/1 "2025-05-28T02:38:41Z")

</div>

I am trying to trigger an alert using anomaly detector by looking at multiple metrics . As an example when&nbsp;dt.host.disk.avail is less than 100GB and&nbsp;dt.host.disk.free is less than 10%&nbsp; . Both the condition should match to trigger a alert . I know anomaly detectors only support single metric, so&nbsp; idea was to include a condition and set the threshold based on the condition value . Below is an example DQL

```markup
timeseries { availableDiskSpace = avg(dt.host.disk.avail),
diskUsed = avg(dt.host.disk.used),
diskFreePercent = avg(dt.host.disk.free)
},
by: { dt.entity.host, dt.entity.disk }, interval: 1m,

filter: { matchesValue(entityAttr(dt.entity.host, "entity.name"), { "HOST16"}) AND matchesValue(entityAttr(dt.entity.disk, "entity.name"), "X:\\") }

| fieldsAdd condition = if(arrayAvg(diskFreePercent) < 10 AND arrayAvg(availableDiskSpace) < 29770882367488, 1, else: 0)
| fieldsRemove availableDiskSpace, diskUsed, diskFreePercent

```

But the output is not really in a timeseries format so&nbsp;anomaly detector does not accept .

I am looking for some ideas on how to best modify the DQL to suite my use case please

---

<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:** [May 28, 2025, 12:40pm UTC](https://community.dynatrace.com/t/dql-for-anomaly-detector-to-compare-multiple-metrics-and-trigger-alert/51851/2 "2025-05-28T12:40:46Z")

</div>

You can use an [iterative expression](https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-query-language/operators#iterative-expressions), which uses square bracket notation (‘[]’), to form a new timeseries array using conditional logic. The expression will iterate through each datapoint in the ‘diskFreePercent’ and ‘availableDiskSpace’ arrays and apply the logic to calculate whether the value of ‘condition’ should be 0 or 1 at each position. You can then use the ‘condition’ field in your anomaly detector.

The DQL would look something like this:

```javascript
timeseries { availableDiskSpace = avg(dt.host.disk.avail),
diskUsed = avg(dt.host.disk.used),
diskFreePercent = avg(dt.host.disk.free)
},
by: { dt.entity.host, dt.entity.disk }, interval: 1m,

filter: { matchesValue(entityAttr(dt.entity.host, "entity.name"), { "HOST16"}) AND matchesValue(entityAttr(dt.entity.disk, "entity.name"), "X:\\") }

| fieldsAdd condition[] = if(diskFreePercent[] < 10 AND availableDiskSpace[] < 29770882367488, 1, else: 0)
| fieldsRemove availableDiskSpace, diskUsed, diskFreePercent

```

I hope this helps 🙂

---

<div class="post-metadata">

**Author:** ![p\_devulapalli](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/p_devulapalli/32/41590_2.png) [@p\_devulapalli](https://community.dynatrace.com/u/p_devulapalli)\
**Post date:** [May 28, 2025, 10:01pm UTC](https://community.dynatrace.com/t/dql-for-anomaly-detector-to-compare-multiple-metrics-and-trigger-alert/51851/3 "2025-05-28T22:01:27Z")

</div>

Thank you for the tip&nbsp;[@marco\_irmer](https://community.dynatrace.com/user/19769)&nbsp;, that helped

---

<div class="post-metadata">

**Author:** ![MarwanC](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marwanc/32/34480_2.png) [@MarwanC](https://community.dynatrace.com/u/MarwanC)\
**Post date:** [July 24, 2025, 11:57am UTC](https://community.dynatrace.com/t/dql-for-anomaly-detector-to-compare-multiple-metrics-and-trigger-alert/51851/4 "2025-07-24T11:57:22Z")

</div>

is timeseries all on one line, would be kind to tidyup the format?
