# Filter by Management Zone using DQL

**URL:** <https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267>\
**Category:** Dashboarding\
**Tags:** dynatrace-managed, data-explorer, latest-dynatrace, dashboards, dashboards-classic\
**Created:** [December 18, 2023, 5:21pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267 "2023-12-18T17:21:10Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![badgerfifteen](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@badgerfifteen](https://community.dynatrace.com/u/badgerfifteen)\
**Post date:** [December 18, 2023, 5:21pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/1 "2023-12-18T17:21:10Z")

</div>

I have a widget on the new Dynatrace dashboard which displays the disk usage of servers. In our estate, we have filtered out servers through to their management zones. In the old dashboard format, you could filter servers by the management zone easily. However, in the newest one, there isn’t such an option available so the next best thing is filtering through DQL. However, I cannot find such a command to do this. Any ideas?

---

<div class="post-metadata">

**Author:** ![cesarsaravia](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/cesarsaravia/32/12818_2.png) [@cesarsaravia](https://community.dynatrace.com/u/cesarsaravia)\
**Post date:** [December 18, 2023, 6:18pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/2 "2023-12-18T18:18:24Z")

</div>

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

On the dashboard 3rd Gen, you can use variable as filters. And the DQL you can use could be this:

Variable:

```markup
fetch dt.entity.host
| fields managementZones

```

Dashboard:

```markup
timeseries usage=avg(dt.host.disk.used), by:{dt.entity.host}
| lookup [ 
      fetch dt.entity.host
      | expand managementZones
    ], sourceField:dt.entity.host, lookupField:id, prefix:"mzone."
| filter mzone.managementZones == $VARIABLE_NAME

```

Example:

 ![cesarsaravia_0-1702923128967.png](https://global.discourse-cdn.com/dynatrace/original/3X/8/d/8d69cc3130a611ac4ae712434cdba9c8a3e9ad07.png)

 ![cesarsaravia_1-1702923475834.png](https://global.discourse-cdn.com/dynatrace/original/3X/4/5/452b6da1dbdf9122e8fa1974675e078556153abe.png)

---

<div class="post-metadata">

**Author:** ![RPbiaggio](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@RPbiaggio](https://community.dynatrace.com/u/RPbiaggio)\
**Post date:** [February 23, 2024, 6:43pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/3 "2024-02-23T18:43:41Z")

</div>

[@cesarsaravia](https://community.dynatrace.com/user/30478)&nbsp;Can I do something similar to filter my open issues by management zone?

---

<div class="post-metadata">

**Author:** ![cesarsaravia](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/cesarsaravia/32/12818_2.png) [@cesarsaravia](https://community.dynatrace.com/u/cesarsaravia)\
**Post date:** [February 23, 2024, 10:01pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/4 "2024-02-23T22:01:28Z")

</div>

Hi&nbsp;[@RPbiaggio](https://community.dynatrace.com/user/67564)&nbsp;  
Here you have a list of dashboards created for GEN3  
[GitHub - TechShady/Dynatrace-Dashboards-Gen3: This repo provides Business Grade Dashboards for Dynatrace Gen3.](https://github.com/TechShady/Dynatrace-Dashboards-Gen3)  
Also, here you have a Zip with the DQL for the problem analysis. You should have to modify it in order to get the MZone filter.

 ![cesarsaravia_0-1708725580983.png](https://global.discourse-cdn.com/dynatrace/original/3X/4/1/414ba8fa09dc1e842b658a4a5a4f64d3d7c4cfb8.png)  
[Problem Analysis.zip](https://community.dynatrace.com/uploads/short-url/jQOXXavaox8h4qOt9xTg5WcQdcC.zip) (3.44 KB)

---

<div class="post-metadata">

**Author:** ![RPbiaggio](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@RPbiaggio](https://community.dynatrace.com/u/RPbiaggio)\
**Post date:** [February 26, 2024, 12:38pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/5 "2024-02-26T12:38:12Z")

</div>

[@cesarsaravia](https://community.dynatrace.com/user/30478)&nbsp;Hi!!

Thanks for the response. I was already looking at this same dashboard. I still haven’t been able to get data collection to work when I include management zones.

---

<div class="post-metadata">

**Author:** ![RPbiaggio](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@RPbiaggio](https://community.dynatrace.com/u/RPbiaggio)\
**Post date:** [February 26, 2024, 4:23pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/6 "2024-02-26T16:23:44Z")

</div>

[@cesarsaravia](https://community.dynatrace.com/user/30478)An example of what I mentioned above. I got a ready-made template and I’m just trying to include the management zone, to be shown, but it returns null.

 ![RPbiaggio_1-1708964568456.png](https://global.discourse-cdn.com/dynatrace/original/3X/5/d/5d47aa90e91dbeede1debea4b23e0b0260a8985a.png)

```markup
fetch events
| fieldsAdd tags = entity_tags, zonas = affected_entities.management_zones.names
| expand tags
| expand zonas
| filter event.kind == "DAVIS_PROBLEM" //and zonas == "FS: Aquisição Digital"
| sort timestamp desc

// Lookup for affected_entity_ids and root_cause_entity_id Start
| expand affected_entity_ids
| expand root_cause_entity_id
| lookup [fetch dt.entity.service], sourceField:affected_entity_ids, lookupField: id, prefix:"lookup.affected.entity.services"
| lookup [fetch dt.entity.service], sourceField:root_cause_entity_id, lookupField: id, prefix:"lookup.rootcause.entity.services"
| lookup [fetch dt.entity.process_group_instance], sourceField:affected_entity_ids, lookupField: id, prefix:"lookup.affected.entity.pgi"
| lookup [fetch dt.entity.process_group_instance], sourceField:root_cause_entity_id, lookupField: id, prefix:"lookup.rootcause.entity.pgi"
| lookup [fetch dt.entity.application], sourceField:affected_entity_ids, lookupField: id, prefix:"lookup.affected.entity.applications"
| lookup [fetch dt.entity.application], sourceField:root_cause_entity_id, lookupField: id, prefix:"lookup.rootcause.entity.applications"
| lookup [fetch dt.entity.mobile_application], sourceField:affected_entity_ids, lookupField: id, prefix:"lookup.affected.entity.mobile"
| lookup [fetch dt.entity.mobile_application], sourceField:root_cause_entity_id, lookupField: id, prefix:"lookup.rootcause.entity.mobile"
| lookup [fetch dt.entity.custom_application], sourceField:affected_entity_ids, lookupField: id, prefix:"lookup.affected.entity.customapplication"
| lookup [fetch dt.entity.custom_application], sourceField:root_cause_entity_id, lookupField: id, prefix:"lookup.rootcause.entity.customapplication"
| lookup [fetch dt.entity.cloud_application], sourceField:affected_entity_ids, lookupField: id, prefix:"lookup.affected.entity.cloudapplication"
| lookup [fetch dt.entity.cloud_application], sourceField:root_cause_entity_id, lookupField: id, prefix:"lookup.rootcause.entity.cloudapplication"
| lookup [fetch dt.entity.synthetic_test], sourceField:affected_entity_ids, lookupField: id, prefix:"lookup.affected.entity.synthetictest"
| lookup [fetch dt.entity.synthetic_test], sourceField:root_cause_entity_id, lookupField: id, prefix:"lookup.rootcause.entity.synthetictest"
| lookup [fetch dt.entity.http_check], sourceField:affected_entity_ids, lookupField: id, prefix:"lookup.affected.entity.httpcheck"
| lookup [fetch dt.entity.http_check], sourceField:root_cause_entity_id, lookupField: id, prefix:"lookup.rootcause.entity.httpcheck"
| lookup [fetch dt.entity.kubernetes_cluster], sourceField:affected_entity_ids, lookupField: id, prefix:"lookup.affected.entity.kubernetescluster"
| lookup [fetch dt.entity.kubernetes_cluster], sourceField:root_cause_entity_id, lookupField: id, prefix:"lookup.rootcause.entity.kubernetescluster"
| lookup [fetch dt.entity.host], sourceField:affected_entity_ids, lookupField: id, prefix:"lookup.affected.entity.hosts"
| lookup [fetch dt.entity.host], sourceField:root_cause_entity_id, lookupField: id, prefix:"lookup.rootcause.entity.hosts"
| lookup [fetch dt.entity.custom_device], sourceField:affected_entity_ids, lookupField: id, prefix:"lookup.affected.entity.customdevices"
| lookup [fetch dt.entity.custom_device], sourceField:root_cause_entity_id, lookupField: id, prefix:"lookup.rootcause.entity.customdevices"
| lookup [fetch dt.entity.hypervisor], sourceField:affected_entity_ids, lookupField: id, prefix:"lookup.affected.entity.hypervisor"
| lookup [fetch dt.entity.hypervisor], sourceField:root_cause_entity_id, lookupField: id, prefix:"lookup.rootcause.entity.hypervisor"
| lookup [fetch dt.entity.environment], sourceField:affected_entity_ids, lookupField: id, prefix:"lookup.affected.entity.environment"
// Lookup for affected_entity_ids and root_cause_entity_id End

| summarize {zonas = takeFirst(zonas),startTime = takeFirst(event.start),
            endTime = takeFirst(event.end),
            problemClosedDuration = takeFirst(resolved_problem_duration),
            status = takeFirst(event.status),
            event.name = takeFirst(event.name),
            severityLevel = takeFirst(event.category),
            affected = takeFirst(affected_entity_ids),
            rootCause = takeFirst(root_cause_entity_id),
            dt.davis.is_duplicate = takeFirst(dt.davis.is_duplicate),
            affectedServices = collectDistinct(lookup.affected.entity.servicesentity.name),
            affectedPGI = collectDistinct(lookup.affected.entity.pgientity.name),
            affectedApplications = collectDistinct(lookup.affected.entity.applicationsentity.name),
            affectedMobile = collectDistinct(lookup.affected.entity.mobileentity.name),
            affectedCustomApplication = collectDistinct(lookup.affected.entity.customapplicationentity.name),
            affectedCloudApplication = collectDistinct(lookup.affected.entity.cloudapplicationentity.name),
            affectedSyntheticTest = collectDistinct(lookup.affected.entity.synthetictestentity.name),
            affectedEntityZone = takeFirst(affected_entity.management_zones.names),
            affectedHttpCheck = collectDistinct(lookup.affected.entity.httpcheckentity.name),
            affectedKubernetesCluster = collectDistinct(lookup.affected.entity.kubernetesclusterentity.name),
            affectedHosts = collectDistinct(lookup.affected.entity.hostsentity.name),
            affectedCustomDevices = collectDistinct(lookup.affected.entity.customdevicesentity.name),
            affectedHypervisor = collectDistinct(lookup.affected.entity.hypervisorentity.name),
            affectedEnvironment = collectDistinct(lookup.affected.entity.environmententity.name),
            rootCauseServices = collectDistinct(lookup.rootcause.entity.servicesentity.name),
            rootCausePGI = collectDistinct(lookup.rootcause.entity.pgientity.name),
            rootCauseApplications = collectDistinct(lookup.rootcause.entity.applicationsentity.name),
            rootCauseMobile = collectDistinct(lookup.rootcause.entity.mobileentity.name),
            rootCauseCustomApplication = collectDistinct(lookup.rootcause.entity.customapplicationentity.name),
            rootCauseSyntheticTest = collectDistinct(lookup.rootcause.entity.synthetictestentity.name),
            rootCauseHttpCheck = collectDistinct(lookup.rootcause.entity.httpcheckentity.name),
            rootCauseHosts = collectDistinct(lookup.rootcause.entity.hostsentity.name),
            rootCauseCustomDevices = collectDistinct(lookup.rootcause.entity.customdevicesentity.name),
            event.id = takeFirst(event.id)}, 
            by:{display_id}
| filter `dt.davis.is_duplicate` == false
| fieldsAdd currentTime = toTimestamp(now())
| fieldsAdd status = if((status == "ACTIVE"),"OPEN", 
                else:if((status == "CLOSED"), "CLOSED"))

| fields zonas,Status = if((status == "OPEN"),"🔴 OPEN", 
                  else:if((status == "CLOSED"),"🟢 CLOSED")),
         Problem = concat(display_id," - ",event.name),         
         Severity = severityLevel,
         Type = (event.name),
         AffectedCount = arraySize(arrayRemoveNulls(arrayConcat(affectedApplications,affectedMobile,affectedCustomApplication,affectedCloudApplication,affectedSyntheticTest,affectedHttpCheck,affectedServices,affectedPGI,affectedKubernetesCluster,affectedHosts,affectedHypervisor,affectedCustomDevices,affectedEnvironment))),
         Affected = arrayRemoveNulls(arrayConcat(zonas,affectedApplications,affectedMobile,affectedCustomApplication,affectedCloudApplication,affectedSyntheticTest,affectedHttpCheck,affectedServices,affectedPGI,affectedKubernetesCluster,affectedHosts,affectedHypervisor,affectedCustomDevices,affectedEnvironment)),
         RootCause = arrayRemoveNulls(arrayConcat(rootCauseServices,rootCauseHosts)),
         StartTime = startTime,
         EndTime = if((status == "OPEN"),"In Progress", 
                    else:if((status == "CLOSED"),endTime)),   
         `Duration (min)` = if((status == "CLOSED"),problemClosedDuration/60000000000,
                   else:if((status == "OPEN"), toLong(currentTime-startTime)/60000000000)),         
         event.id           
| sort StartTime, direction:"descending"
| sort Status, direction:"ascending"

```

---

<div class="post-metadata">

**Author:** ![cesarsaravia](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/cesarsaravia/32/12818_2.png) [@cesarsaravia](https://community.dynatrace.com/u/cesarsaravia)\
**Post date:** [February 27, 2024, 10:59pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/7 "2024-02-27T22:59:45Z")

</div>

Hi&nbsp;[@RPbiaggio](https://community.dynatrace.com/user/67564)&nbsp;  
After all the lookups, you must add this code and then get the right **lookup.affected.entity.** …

```markup
| fieldsAdd zonas = coalesce(lookup.affected.entity.hostsmanagementZones, lookup.affected.entity.hypervisormanagementZones,lookup.affected.entity.servicesmanagementZones)

```

Example:

 ![cesarsaravia_0-1709074680370.png](https://global.discourse-cdn.com/dynatrace/original/3X/e/5/e5bba1b7291a3cdc7125871bd4f24c7c5937074c.jpeg)

---

<div class="post-metadata">

**Author:** ![tonicbenn2023](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tonicbenn2023](https://community.dynatrace.com/u/tonicbenn2023)\
**Post date:** [March 28, 2024, 9:06pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/8 "2024-03-28T21:06:15Z")

</div>

How do you use the query you’ve drafted above but for process group filtering by management zone? Below is the DQL query I have without filtering by management zone but would like the variable that I’ve created based on your above example to help filter out the process groups on each host in a specific mz:

Variable:

```java
fetch dt.entity.process_group
| fields managementZones
| sort managementZones asc

```

DQL Query:

```java
timeseries cpuUsage = avg(dt.process.cpu.usage), by:{host.name, dt.entity.process_group} 
| fieldsAdd pgname = lookup([fetch dt.entity.process_group], lookupField:id, sourceField:dt.entity.process_group)[entity.name]
| sort arrayAvg(cpuUsage) desc
| limit 5

```

---

<div class="post-metadata">

**Author:** ![cesarsaravia](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/cesarsaravia/32/12818_2.png) [@cesarsaravia](https://community.dynatrace.com/u/cesarsaravia)\
**Post date:** [March 29, 2024, 6:03pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/9 "2024-03-29T18:03:35Z")

</div>

Hey&nbsp;[@tonicbenn2023](https://community.dynatrace.com/user/65736)&nbsp;  
You still can use your DQL for Mzone variables, but the DQL you should use for this scenario is:

```markup
timeseries cpuUsage = avg(dt.process.cpu.usage), by:{host.name, dt.entity.process_group} 
| lookup [fetch dt.entity.process_group], lookupField:id, sourceField:dt.entity.process_group,prefix:"lookup.pg" //[entity.name]
| fieldsAdd lookup.pgentity.name,mzone= lookup.pgmanagementZones
| expand mzone
| filter toString(mzone)==$VARIABLE_MZONE
| sort arrayAvg(cpuUsage) desc
| limit 5

```

Result:

 ![cesarsaravia_0-1711735381600.png](https://global.discourse-cdn.com/dynatrace/original/2X/0/01d6a5f530639df1513a1ae6c0b1a035fe4b790e.png)

Regards,

---

<div class="post-metadata">

**Author:** ![tonicbenn2023](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tonicbenn2023](https://community.dynatrace.com/u/tonicbenn2023)\
**Post date:** [April 1, 2024, 1:38pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/10 "2024-04-01T13:38:16Z")

</div>

Amazing! This worked, thank you :-)!

---

<div class="post-metadata">

**Author:** ![andruccioli50](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@andruccioli50](https://community.dynatrace.com/u/andruccioli50)\
**Post date:** [May 23, 2024, 3:24pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/11 "2024-05-23T15:24:09Z")

</div>

Thanks for the help [@cesarsaravia](https://community.dynatrace.com/user/30478)&nbsp;, if I don’t bother you too much, I’d like to ask you how to filter the data in the dashboard above for a specific Management zone (in my case the Management Zone is a dynamic variable), couldn’t figured it out where to add the filter statement.

This is the query in DQL (same Davis Problems’s Dashboard as&nbsp;[@RPbiaggio](https://community.dynatrace.com/user/67564) )

fetch events  
| fieldsAdd tags = entity\_tags, zone = affected\_entities.management\_zones.names  
| expand tags  
| expand zone  
| filter event.kind == “DAVIS\_PROBLEM” //and zonas == “FS: Aquisição Digital”  
| sort timestamp desc

// Lookup for affected\_entity\_ids and root\_cause\_entity\_id Start  
| expand affected\_entity\_ids  
| expand root\_cause\_entity\_id  
| lookup [fetch dt.entity.service], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.services”  
| lookup [fetch dt.entity.service], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.services”  
| lookup [fetch dt.entity.process\_group\_instance], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.pgi”  
| lookup [fetch dt.entity.process\_group\_instance], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.pgi”  
| lookup [fetch dt.entity.application], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.applications”  
| lookup [fetch dt.entity.application], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.applications”  
| lookup [fetch dt.entity.mobile\_application], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.mobile”  
| lookup [fetch dt.entity.mobile\_application], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.mobile”  
| lookup [fetch dt.entity.custom\_application], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.customapplication”  
| lookup [fetch dt.entity.custom\_application], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.customapplication”  
| lookup [fetch dt.entity.cloud\_application], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.cloudapplication”  
| lookup [fetch dt.entity.cloud\_application], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.cloudapplication”  
| lookup [fetch dt.entity.synthetic\_test], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.synthetictest”  
| lookup [fetch dt.entity.synthetic\_test], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.synthetictest”  
| lookup [fetch dt.entity.http\_check], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.httpcheck”  
| lookup [fetch dt.entity.http\_check], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.httpcheck”  
| lookup [fetch dt.entity.kubernetes\_cluster], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.kubernetescluster”  
| lookup [fetch dt.entity.kubernetes\_cluster], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.kubernetescluster”  
| lookup [fetch dt.entity.host], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.hosts”  
| lookup [fetch dt.entity.host], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.hosts”  
| lookup [fetch dt.entity.custom\_device], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.customdevices”  
| lookup [fetch dt.entity.custom\_device], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.customdevices”  
| lookup [fetch dt.entity.hypervisor], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.hypervisor”  
| lookup [fetch dt.entity.hypervisor], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.hypervisor”  
| lookup [fetch dt.entity.environment], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.environment”  
// Lookup for affected\_entity\_ids and root\_cause\_entity\_id End

| fieldsAdd zone = coalesce(lookup.affected.entity.hostsmanagementZones, lookup.affected.entity.hypervisormanagementZones,lookup.affected.entity.servicesmanagementZones)

// | summarize {zone = takeFirst(zone),startTime = takeFirst(event.start),  
| summarize {zone = takeFirst(zone),startTime = takeFirst(event.start),  
endTime = takeFirst(event.end),  
problemClosedDuration = takeFirst(resolved\_problem\_duration),  
status = takeFirst(event.status),  
event.name = takeFirst(event.name),  
severityLevel = takeFirst(event.category),  
affected = takeFirst(affected\_entity\_ids),  
rootCause = takeFirst(root\_cause\_entity\_id),  
dt.davis.is\_duplicate = takeFirst(dt.davis.is\_duplicate),  
affectedServices = collectDistinct(lookup.affected.entity.servicesentity.name),  
affectedPGI = collectDistinct(lookup.affected.entity.pgientity.name),  
affectedApplications = collectDistinct(lookup.affected.entity.applicationsentity.name),  
affectedMobile = collectDistinct(lookup.affected.entity.mobileentity.name),  
affectedCustomApplication = collectDistinct(lookup.affected.entity.customapplicationentity.name),  
affectedCloudApplication = collectDistinct(lookup.affected.entity.cloudapplicationentity.name),  
affectedSyntheticTest = collectDistinct(lookup.affected.entity.synthetictestentity.name),  
affectedEntityZone = takeFirst(affected\_entity.management\_zones.names),  
affectedHttpCheck = collectDistinct(lookup.affected.entity.httpcheckentity.name),  
affectedKubernetesCluster = collectDistinct(lookup.affected.entity.kubernetesclusterentity.name),  
affectedHosts = collectDistinct(lookup.affected.entity.hostsentity.name),  
affectedCustomDevices = collectDistinct(lookup.affected.entity.customdevicesentity.name),  
affectedHypervisor = collectDistinct(lookup.affected.entity.hypervisorentity.name),  
affectedEnvironment = collectDistinct(lookup.affected.entity.environmententity.name),  
rootCauseServices = collectDistinct(lookup.rootcause.entity.servicesentity.name),  
rootCausePGI = collectDistinct(lookup.rootcause.entity.pgientity.name),  
rootCauseApplications = collectDistinct(lookup.rootcause.entity.applicationsentity.name),  
rootCauseMobile = collectDistinct(lookup.rootcause.entity.mobileentity.name),  
rootCauseCustomApplication = collectDistinct(lookup.rootcause.entity.customapplicationentity.name),  
rootCauseSyntheticTest = collectDistinct(lookup.rootcause.entity.synthetictestentity.name),  
rootCauseHttpCheck = collectDistinct(lookup.rootcause.entity.httpcheckentity.name),  
rootCauseHosts = collectDistinct(lookup.rootcause.entity.hostsentity.name),  
rootCauseCustomDevices = collectDistinct(lookup.rootcause.entity.customdevicesentity.name),  
event.id = takeFirst(event.id)},  
by:{display\_id}  
| filter `dt.davis.is_duplicate` == false  
| fieldsAdd currentTime = toTimestamp(now())  
| fieldsAdd status = if((status == “ACTIVE”),“OPEN”,  
else:if((status == “CLOSED”), “CLOSED”))

| fields zone,Status = if((status == “OPEN”)," OPEN",  
else:if((status == “CLOSED”),“🟢 CLOSED”)),  
Problem = concat(display\_id," - ",event.name),  
Severity = severityLevel,  
Type = (event.name),  
AffectedCount = arraySize(arrayRemoveNulls(arrayConcat(affectedApplications,affectedMobile,affectedCustomApplication,affectedCloudApplication,affectedSyntheticTest,affectedHttpCheck,affectedServices,affectedPGI,affectedKubernetesCluster,affectedHosts,affectedHypervisor,affectedCustomDevices,affectedEnvironment))),  
Affected = arrayRemoveNulls(arrayConcat(zone,affectedApplications,affectedMobile,affectedCustomApplication,affectedCloudApplication,affectedSyntheticTest,affectedHttpCheck,affectedServices,affectedPGI,affectedKubernetesCluster,affectedHosts,affectedHypervisor,affectedCustomDevices,affectedEnvironment)),  
RootCause = arrayRemoveNulls(arrayConcat(rootCauseServices,rootCauseHosts)),  
StartTime = startTime,  
EndTime = if((status == “OPEN”),“In Progress”,  
else:if((status == “CLOSED”),endTime)),  
`Duration (min)` = if((status == “CLOSED”),problemClosedDuration/60000000000,  
else:if((status == “OPEN”), toLong(currentTime-startTime)/60000000000)),  
event.id  
| sort StartTime, direction:“descending”  
| sort Status, direction:“ascending”

My dynamic variable name is called&nbsp; **MZ** and the query is this one

fetch dt.entity.host  
| expand managementZones  
| fields managementZones

Thanks in advance

---

<div class="post-metadata">

**Author:** ![andruccioli50](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@andruccioli50](https://community.dynatrace.com/u/andruccioli50)\
**Post date:** [May 24, 2024, 8:02am UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/12 "2024-05-24T08:02:06Z")

</div>

Hi&nbsp;[@cesarsaravia](https://community.dynatrace.com/user/30478)&nbsp; sorry to bother you, I’d like to ask you another thing on the same dashboard you were looking with&nbsp;[@RPbiaggio](https://community.dynatrace.com/user/67564)&nbsp; , how can I manage to filter data inside the Dashboard only for the Management Zone specified in a dynamic variable?

This is my variable (called MZ)

fetch dt.entity.host  
| expand managementZones  
| fields managementZones

This is my dashboard, the same as RPBiaggio:

fetch events  
| fieldsAdd tags = entity\_tags, zone = affected\_entities.management\_zones.names  
| expand tags  
| expand zone  
| filter event.kind == “DAVIS\_PROBLEM” //and zonas == “FS: Aquisição Digital”  
| sort timestamp desc

// Lookup for affected\_entity\_ids and root\_cause\_entity\_id Start  
| expand affected\_entity\_ids  
| expand root\_cause\_entity\_id  
| lookup [fetch dt.entity.service], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.services”  
| lookup [fetch dt.entity.service], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.services”  
| lookup [fetch dt.entity.process\_group\_instance], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.pgi”  
| lookup [fetch dt.entity.process\_group\_instance], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.pgi”  
| lookup [fetch dt.entity.application], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.applications”  
| lookup [fetch dt.entity.application], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.applications”  
| lookup [fetch dt.entity.mobile\_application], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.mobile”  
| lookup [fetch dt.entity.mobile\_application], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.mobile”  
| lookup [fetch dt.entity.custom\_application], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.customapplication”  
| lookup [fetch dt.entity.custom\_application], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.customapplication”  
| lookup [fetch dt.entity.cloud\_application], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.cloudapplication”  
| lookup [fetch dt.entity.cloud\_application], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.cloudapplication”  
| lookup [fetch dt.entity.synthetic\_test], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.synthetictest”  
| lookup [fetch dt.entity.synthetic\_test], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.synthetictest”  
| lookup [fetch dt.entity.http\_check], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.httpcheck”  
| lookup [fetch dt.entity.http\_check], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.httpcheck”  
| lookup [fetch dt.entity.kubernetes\_cluster], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.kubernetescluster”  
| lookup [fetch dt.entity.kubernetes\_cluster], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.kubernetescluster”  
| lookup [fetch dt.entity.host], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.hosts”  
| lookup [fetch dt.entity.host], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.hosts”  
| lookup [fetch dt.entity.custom\_device], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.customdevices”  
| lookup [fetch dt.entity.custom\_device], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.customdevices”  
| lookup [fetch dt.entity.hypervisor], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.hypervisor”  
| lookup [fetch dt.entity.hypervisor], sourceField:root\_cause\_entity\_id, lookupField: id, prefix:“lookup.rootcause.entity.hypervisor”  
| lookup [fetch dt.entity.environment], sourceField:affected\_entity\_ids, lookupField: id, prefix:“lookup.affected.entity.environment”  
// Lookup for affected\_entity\_ids and root\_cause\_entity\_id End

| fieldsAdd zone = coalesce(lookup.affected.entity.hostsmanagementZones, lookup.affected.entity.hypervisormanagementZones,lookup.affected.entity.servicesmanagementZones)

// | summarize {zone = takeFirst(zone),startTime = takeFirst(event.start),  
| summarize {zone = takeFirst(zone),startTime = takeFirst(event.start),  
endTime = takeFirst(event.end),  
problemClosedDuration = takeFirst(resolved\_problem\_duration),  
status = takeFirst(event.status),  
event.name = takeFirst(event.name),  
severityLevel = takeFirst(event.category),  
affected = takeFirst(affected\_entity\_ids),  
rootCause = takeFirst(root\_cause\_entity\_id),  
dt.davis.is\_duplicate = takeFirst(dt.davis.is\_duplicate),  
affectedServices = collectDistinct(lookup.affected.entity.servicesentity.name),  
affectedPGI = collectDistinct(lookup.affected.entity.pgientity.name),  
affectedApplications = collectDistinct(lookup.affected.entity.applicationsentity.name),  
affectedMobile = collectDistinct(lookup.affected.entity.mobileentity.name),  
affectedCustomApplication = collectDistinct(lookup.affected.entity.customapplicationentity.name),  
affectedCloudApplication = collectDistinct(lookup.affected.entity.cloudapplicationentity.name),  
affectedSyntheticTest = collectDistinct(lookup.affected.entity.synthetictestentity.name),  
affectedEntityZone = takeFirst(affected\_entity.management\_zones.names),  
affectedHttpCheck = collectDistinct(lookup.affected.entity.httpcheckentity.name),  
affectedKubernetesCluster = collectDistinct(lookup.affected.entity.kubernetesclusterentity.name),  
affectedHosts = collectDistinct(lookup.affected.entity.hostsentity.name),  
affectedCustomDevices = collectDistinct(lookup.affected.entity.customdevicesentity.name),  
affectedHypervisor = collectDistinct(lookup.affected.entity.hypervisorentity.name),  
affectedEnvironment = collectDistinct(lookup.affected.entity.environmententity.name),  
rootCauseServices = collectDistinct(lookup.rootcause.entity.servicesentity.name),  
rootCausePGI = collectDistinct(lookup.rootcause.entity.pgientity.name),  
rootCauseApplications = collectDistinct(lookup.rootcause.entity.applicationsentity.name),  
rootCauseMobile = collectDistinct(lookup.rootcause.entity.mobileentity.name),  
rootCauseCustomApplication = collectDistinct(lookup.rootcause.entity.customapplicationentity.name),  
rootCauseSyntheticTest = collectDistinct(lookup.rootcause.entity.synthetictestentity.name),  
rootCauseHttpCheck = collectDistinct(lookup.rootcause.entity.httpcheckentity.name),  
rootCauseHosts = collectDistinct(lookup.rootcause.entity.hostsentity.name),  
rootCauseCustomDevices = collectDistinct(lookup.rootcause.entity.customdevicesentity.name),  
event.id = takeFirst(event.id)},  
by:{display\_id}  
| filter `dt.davis.is_duplicate` == false  
| fieldsAdd currentTime = toTimestamp(now())  
| fieldsAdd status = if((status == “ACTIVE”),“OPEN”,  
else:if((status == “CLOSED”), “CLOSED”))

| fields zone,Status = if((status == “OPEN”)," OPEN",  
else:if((status == “CLOSED”),“🟢 CLOSED”)),  
Problem = concat(display\_id," - ",event.name),  
Severity = severityLevel,  
Type = (event.name),  
AffectedCount = arraySize(arrayRemoveNulls(arrayConcat(affectedApplications,affectedMobile,affectedCustomApplication,affectedCloudApplication,affectedSyntheticTest,affectedHttpCheck,affectedServices,affectedPGI,affectedKubernetesCluster,affectedHosts,affectedHypervisor,affectedCustomDevices,affectedEnvironment))),  
Affected = arrayRemoveNulls(arrayConcat(zone,affectedApplications,affectedMobile,affectedCustomApplication,affectedCloudApplication,affectedSyntheticTest,affectedHttpCheck,affectedServices,affectedPGI,affectedKubernetesCluster,affectedHosts,affectedHypervisor,affectedCustomDevices,affectedEnvironment)),  
RootCause = arrayRemoveNulls(arrayConcat(rootCauseServices,rootCauseHosts)),  
StartTime = startTime,  
EndTime = if((status == “OPEN”),“In Progress”,  
else:if((status == “CLOSED”),endTime)),  
`Duration (min)` = if((status == “CLOSED”),problemClosedDuration/60000000000,  
else:if((status == “OPEN”), toLong(currentTime-startTime)/60000000000)),  
event.id  
| sort StartTime, direction:“descending”  
| sort Status, direction:“ascending”

Where should I add the additional filter for my variable MZ?&nbsp; Couldn’t figured it out, thanks in advance

---

<div class="post-metadata">

**Author:** ![RPbiaggio](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@RPbiaggio](https://community.dynatrace.com/u/RPbiaggio)\
**Post date:** [May 31, 2024, 12:27pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/13 "2024-05-31T12:27:13Z")

</div>

Oops, how are you? I don’t know if I understand the question, but have you tried using this instruction to filter with your variable?

```markup
| filter in(zone ,array($MZ))

```

---

<div class="post-metadata">

**Author:** ![Mangordi89](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@Mangordi89](https://community.dynatrace.com/u/Mangordi89)\
**Post date:** [June 27, 2024, 7:45pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/14 "2024-06-27T19:45:52Z")

</div>

This repo is not working

---

<div class="post-metadata">

**Author:** ![Vrushali](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vrushali](https://community.dynatrace.com/u/Vrushali)\
**Post date:** [September 18, 2024, 6:39pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/15 "2024-09-18T18:39:47Z")

</div>

Can we filter by ManagementZone for davis problem?

for example this query,

fetch dt.davis.problems  
| filter event.category == “ERROR”  
| sort count desc

I want to filter the records based on MZ in new dashboard, is it possible?

---

<div class="post-metadata">

**Author:** ![nathan\_tennant](https://avatars.discourse-cdn.com/v4/letter/n/ea666f/32.png) [@nathan\_tennant](https://community.dynatrace.com/u/nathan_tennant)\
**Post date:** [February 12, 2025, 3:34pm UTC](https://community.dynatrace.com/t/filter-by-management-zone-using-dql/43267/16 "2025-02-12T15:34:58Z")

</div>

I have this same question.&nbsp; Did you ever find a solution?
