# Querying CPU Comparison with Custom Tags in DQL

**URL:** <https://community.dynatrace.com/t/querying-cpu-comparison-with-custom-tags-in-dql/48087>\
**Category:** DQL\
**Tags:** dql, dynatrace-managed, hosts-classic, notebooks, infrastructure-operations\
**Created:** [October 2, 2024, 11:47am UTC](https://community.dynatrace.com/t/querying-cpu-comparison-with-custom-tags-in-dql/48087 "2024-10-02T11:47:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![VictorRuiz](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/victorruiz/32/32860_2.png) [@VictorRuiz](https://community.dynatrace.com/u/VictorRuiz)\
**Post date:** [October 2, 2024, 11:47am UTC](https://community.dynatrace.com/t/querying-cpu-comparison-with-custom-tags-in-dql/48087/1 "2024-10-02T11:47:45Z")

</div>

Hello everyone,

I am new to the DQL language and I would like to ask if it is possible to make a CPU comparison with the average of all hosts entities that are included by several tags.

Let me explain, I have this query that gives me the average CPU usage of all the hosts that match the filter tags:

_timeseries usage = avg(dt.host.cpu.usage),_  
_filter: { in(dt.entity.host, classicEntitySelector(“type(host),tag(\”APP:FAKE\_APP")}_

On the other hand I have this other query that compares me the CPU consumption of the hosts that match the host.name:

_timeseries cpu=avg(dt.host.cpu.usage),_  
_by:{host.name},_  
_from: -30d_  
_| append [timeseries cpu.30d=avg(dt.host.cpu.usage), by:{host.name}, shift:-30d]_  
_| filter startsWith(host.name, “FAKE\_HOST”)._

My question is if they can be somehow linked so that the filter uses custom tags instead of host.name.

Thank you very much

---

<div class="post-metadata">

**Author:** ![krzysztof\_hoja](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/krzysztof_hoja/32/34625_2.png) [@krzysztof\_hoja](https://community.dynatrace.com/u/krzysztof_hoja)\
**Post date:** [October 3, 2024, 2:39pm UTC](https://community.dynatrace.com/t/querying-cpu-comparison-with-custom-tags-in-dql/48087/2 "2024-10-03T14:39:36Z")

</div>

I am not sure if i captured the need correctly, but here is my example: comparison of individual host CPU usage (only hosts with given tags) and average CPU usage of all hosts for earlier period of time.

```markup
timeseries avg(dt.host.cpu.usage), by: {dt.entity.host}, filter:{ in(dt.entity.host, classicEntitySelector("type(host),tag(Azure:VM)")) }
| append [

  timeseries avg(dt.host.cpu.usage), shift: -7d
  , filter:{ in(dt.entity.host, classicEntitySelector("type(host),tag(Azure:VM)")) }

  | fieldsAdd dt.entity.host = "Reference"

]

```

Result looks like this:

 ![krzysztof_hoja_0-1727966312156.png](https://global.discourse-cdn.com/dynatrace/original/3X/0/f/0f4882fd50a08c2d37f1fdab11880530f01fe24e.png)
