# Counting Problems by ManagementZone

**URL:** <https://community.dynatrace.com/t/counting-problems-by-managementzone/54174>\
**Category:** DQL\
**Tags:** dql, management-zones, problems\
**Created:** [November 23, 2025, 8:12pm UTC](https://community.dynatrace.com/t/counting-problems-by-managementzone/54174 "2025-11-23T20:12:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PVThach](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@PVThach](https://community.dynatrace.com/u/PVThach)\
**Post date:** [November 23, 2025, 8:12pm UTC](https://community.dynatrace.com/t/counting-problems-by-managementzone/54174/1 "2025-11-23T20:12:42Z")

</div>

I am able to get total Hosts, Services, Process Group, Custom Device, etcs by ManagementZone (MZ).  
I am stuck trying to get total number problems associated by MZ (affected\_entity\_ids, and root\_cause\_entity\_id).

Here is what I have:

fetch dt.entity.service  
| expand managementZones  
| summarize by:{managementZones}, service = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))

| append [fetch dt.entity.host | expand managementZones | filterOut isNull(managementZones) | summarize by:{managementZones}, Host = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))]  
| append [fetch dt.entity.process\_group | expand managementZones | filterOut isNull(managementZones) | summarize by:{managementZones}, ProcessGroup = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))]  
| append [fetch dt.entity.application | expand managementZones | filterOut isNull(managementZones) | summarize by:{managementZones}, Application = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))]  
| append [fetch dt.entity.aws\_lambda\_function | expand managementZones | filterOut isNull(managementZones) | summarize by:{managementZones}, AWS\_lambda\_function = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))]  
| append [fetch dt.entity.aws\_credentials | expand managementZones | filterOut isNull(managementZones) | summarize by:{managementZones}, AWS\_credential = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))]  
| append [fetch dt.entity.http\_check | expand managementZones | filterOut isNull(managementZones) | summarize by:{managementZones}, http\_check = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))]  
| append [fetch dt.entity.custom\_device | expand managementZones | filterOut isNull(managementZones) | summarize by:{managementZones}, CustomDevice = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))]  
| append [fetch dt.entity.custom\_device\_group | expand managementZones | filterOut isNull(managementZones) | summarize by:{managementZones}, CustomDeviceGroup = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))]  
| append [fetch dt.entity.relational\_database\_service | expand managementZones | filterOut isNull(managementZones) | summarize by:{managementZones}, relational\_database = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))]  
| append [fetch dt.entity.kubernetes\_service | expand managementZones | filterOut isNull(managementZones) | summarize by:{managementZones}, kubernetes\_service = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))]

// This is where I am having issue: How do I count problems (affected\_entity\_ids, and root\_cause\_entity\_id) by management zone.  
//  
//| append [fetch dt.davis.problems | expand affected\_entity\_ids | expand root\_cause\_entity\_id | summarize by:{display\_id}, AFService = countDistinct(display\_id)]  
//  
// Perhaps append then lookup with sourceField:affected\_entity\_ids and root\_cause\_entity\_id ?

| summarize by:{managementZones},  
Hosts = if ( isNull(max(Host)), 0, else: max(Host) ),  
Services = if ( isNull(max(service)), 0, else: max(service) ),  
ProcessGrp = if ( isNull(max(ProcessGroup)), 0, else: max(ProcessGroup) ),  
CustomDev = if ( isNull(max(CustomDevice)), 0, else: max(CustomDevice) ),  
CustomDevGrp = if ( isNull(max(CustomDeviceGroup)), 0, else: max(CustomDeviceGroup) ),  
Applications = if ( isNull(max(Application)), 0, else: max(Application) ),  
AWS\_lambda = if ( isNull(max(AWS\_lambda\_function)), 0, else: max(AWS\_lambda\_function) ),  
AWS\_credentials = if ( isNull(max(AWS\_credential)), 0, else: max(AWS\_credential) ),  
k8s\_services = if ( isNull(max(kubernetes\_service)), 0, else: max(kubernetes\_service) ),  
RDB = if ( isNull(max(relational\_database)), 0, else: max(relational\_database) ),  
http\_checks = if ( isNull(max(http\_check)), 0, else: max(http\_check) )

| filterOut isNull(managementZones)  
| sort upper(managementZones) asc

---

<div class="post-metadata">

**Author:** ![t\_pawlak](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/t_pawlak/32/14991_2.png) [@t\_pawlak](https://community.dynatrace.com/u/t_pawlak)\
**Post date:** [November 24, 2025, 9:24am UTC](https://community.dynatrace.com/t/counting-problems-by-managementzone/54174/2 "2025-11-24T09:24:44Z")

</div>

Hi,  
try this:

```markup
fetch dt.entity.service
| expand managementZones
| summarize by:{managementZones}, service = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))

| append [
    fetch dt.entity.host
    | expand managementZones
    | filterOut isNull(managementZones)
    | summarize by:{managementZones}, Host = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))
]
| append [
    fetch dt.entity.process_group
    | expand managementZones
    | filterOut isNull(managementZones)
    | summarize by:{managementZones}, ProcessGroup = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))
]
| append [
    fetch dt.entity.application
    | expand managementZones
    | filterOut isNull(managementZones)
    | summarize by:{managementZones}, Application = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))
]
| append [
    fetch dt.entity.aws_lambda_function
    | expand managementZones
    | filterOut isNull(managementZones)
    | summarize by:{managementZones}, AWS_lambda_function = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))
]
| append [
    fetch dt.entity.aws_credentials
    | expand managementZones
    | filterOut isNull(managementZones)
    | summarize by:{managementZones}, AWS_credential = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))
]
| append [
    fetch dt.entity.http_check
    | expand managementZones
    | filterOut isNull(managementZones)
    | summarize by:{managementZones}, http_check = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))
]
| append [
    fetch dt.entity.custom_device
    | expand managementZones
    | filterOut isNull(managementZones)
    | summarize by:{managementZones}, CustomDevice = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))
]
| append [
    fetch dt.entity.custom_device_group
    | expand managementZones
    | filterOut isNull(managementZones)
    | summarize by:{managementZones}, CustomDeviceGroup = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))
]
| append [
    fetch dt.entity.relational_database_service
    | expand managementZones
    | filterOut isNull(managementZones)
    | summarize by:{managementZones}, relational_database = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))
]
| append [
    fetch dt.entity.kubernetes_service
    | expand managementZones
    | filterOut isNull(managementZones)
    | summarize by:{managementZones}, kubernetes_service = if( isNull(countDistinct(id) ), 0, else: countDistinct(id))
]

//
// PROBLEMY – wg affected_entity_ids
//
| append [
    fetch dt.davis.problems
    | expand affected_entity_ids
    // podpinamy encje (tu: SERVICE) żeby z nich wyciągnąć managementZones
    | lookup sourceField:affected_entity_ids, lookupField:id, [
        fetch dt.entity.service
        | expand managementZones
        | filterOut isNull(managementZones)
    ]
    // lookup.managementZones -> normalne pole managementZones
    | expand `lookup.managementZones`, alias:managementZones
    | summarize by:{managementZones}, Problems_affected = countDistinct(display_id)
]

//
// PROBLEMY – wg root_cause_entity_id
//
| append [
    fetch dt.davis.problems
    | filter isNotNull(root_cause_entity_id) and root_cause_entity_id != ""
    | lookup sourceField:root_cause_entity_id, lookupField:id, [
        fetch dt.entity.service
        | expand managementZones
        | filterOut isNull(managementZones)
    ]
    | expand `lookup.managementZones`, alias:managementZones
    | summarize by:{managementZones}, Problems_root_cause = countDistinct(display_id)
]

| summarize by:{managementZones},
    Hosts = if ( isNull(max(Host)), 0, else: max(Host) ),
    Services = if ( isNull(max(service)), 0, else: max(service) ),
    ProcessGrp = if ( isNull(max(ProcessGroup)), 0, else: max(ProcessGroup) ),
    CustomDev = if ( isNull(max(CustomDevice)), 0, else: max(CustomDevice) ),
    CustomDevGrp = if ( isNull(max(CustomDeviceGroup)), 0, else: max(CustomDeviceGroup) ),
    Applications = if ( isNull(max(Application)), 0, else: max(Application) ),
    AWS_lambda = if ( isNull(max(AWS_lambda_function)), 0, else: max(AWS_lambda_function) ),
    AWS_credentials = if ( isNull(max(AWS_credential)), 0, else: max(AWS_credential) ),
    k8s_services = if ( isNull(max(kubernetes_service)), 0, else: max(kubernetes_service) ),
    RDB = if ( isNull(max(relational_database)), 0, else: max(relational_database) ),
    http_checks = if ( isNull(max(http_check)), 0, else: max(http_check) ),
    Problems_affected = if ( isNull(max(Problems_affected)), 0, else: max(Problems_affected) ),
    Problems_root_cause= if ( isNull(max(Problems_root_cause)), 0, else: max(Problems_root_cause) )

| filterOut isNull(managementZones)
| sort upper(managementZones) asc

```

 ![t_pawlak_0-1763976208961.png](https://global.discourse-cdn.com/dynatrace/original/2X/f/fabcfc106ffbb756ea90c5185b644b71f1d3f221.png)

---

<div class="post-metadata">

**Author:** ![PVThach](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@PVThach](https://community.dynatrace.com/u/PVThach)\
**Post date:** [November 25, 2025, 2:24pm UTC](https://community.dynatrace.com/t/counting-problems-by-managementzone/54174/3 "2025-11-25T14:24:12Z")

</div>

Awesome.&nbsp; Thank you.&nbsp; The solution did give me the answer I was looking for.  
I had made a minor change because of IDE warning:

```markup
| expand `lookup.managementZones`, alias:managementZones

```

to

```markup
| fieldsAdd lookup.managementZones, alias:managementZones

```

The IDE warning:  
_Applying the expand command with an alias on an expression that’s not of type array has the same effect as a `fieldsAdd` command. You can replace it with this._
