# Calculation of Percentage of problems with "Summarize" in DQL

**URL:** <https://community.dynatrace.com/t/calculation-of-percentage-of-problems-with-summarize-in-dql/46382>\
**Category:** DQL\
**Tags:** dql\
**Created:** [June 30, 2024, 6:45pm UTC](https://community.dynatrace.com/t/calculation-of-percentage-of-problems-with-summarize-in-dql/46382 "2024-06-30T18:45:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JhonU](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JhonU](https://community.dynatrace.com/u/JhonU)\
**Post date:** [June 30, 2024, 6:45pm UTC](https://community.dynatrace.com/t/calculation-of-percentage-of-problems-with-summarize-in-dql/46382/1 "2024-06-30T18:45:31Z")

</div>

Hello, maybe you could help me, I have a query that counts the total events by category “event.category”, when using the summarize command I cannot calculate the total events in this way to obtain the percentage it represents in an additional column, EX: %=100\*(count per Category/Total)

```markup
fetch events//, from:now()
| filter event.kind == "DAVIS_PROBLEM"
| fieldsAdd dt.entity.service= affected_entity_ids[0]
| fieldsAdd dt.entity.service.name = entityName(dt.entity.service)
| filter event.status_transition == "CREATED"
| summarize a = count(), by:{event.category}

```

 ![JhonU_0-1719772882243.png](https://global.discourse-cdn.com/dynatrace/original/3X/5/2/52406b5dfc7e924be7a7412327a4fc0035b5b103.png)

---

<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:** [July 1, 2024, 3:56pm UTC](https://community.dynatrace.com/t/calculation-of-percentage-of-problems-with-summarize-in-dql/46382/2 "2024-07-01T15:56:35Z")

</div>

It is possible to approach in 2 way to the problem.

1. “Ask again”

```markup
fetch events
| filter event.kind == "DAVIS_PROBLEM"
| filter event.status_transition == "CREATED"
| summarize a = count(), by:{event.category, event.kind}
| lookup [
  fetch events
  | filter event.kind == "DAVIS_PROBLEM"
  | filter event.status_transition == "CREATED"
  | summarize total = count(), by:{event.kind}
], sourceField:event.kind, lookupField:event.kind, fields:{total}
| fields event.category, a, ap=100*a/total

```

Using _ **lookup** _ command you can add (calculated by another query) total count to each of of rows. Then you you can divide particular count by total number of events. Lookup command requires joining fields to be specified. I used event.kind on both sided as it will have only one value for this query and no “fake key” needs to be produced.

 ![krzysztof_hoja_0-1719849063258.png](https://global.discourse-cdn.com/dynatrace/original/3X/e/3/e3b454292685128154ddb7a79468e8a3490ea4ca.png)

1. “summarize + expand”

```markup
fetch events
| filter event.kind == "DAVIS_PROBLEM"
| filter event.status_transition == "CREATED"
| summarize a = count(), by:{event.category}
| summarize { total=sum(a), d=collectArray(record(event.category, a))}
| expand d
| fields event.category=d[event.category], a=d[a], ap=100*d[a]/total

```

After a basic query additional summarization needs to happen. This way we can calculate total (sum of individual counts). In order not to lose details, we need to collect components in arrays of pairs (event.category and a). After summarization we can bring back original row count using _ **expand** _ command after which each row will have total field ready to calculate percentage.

 ![krzysztof_hoja_1-1719849337936.png](https://global.discourse-cdn.com/dynatrace/original/3X/8/3/836d92a46a9f4c4578d3d5ddc1ad311076786131.png)

Kris

---

<div class="post-metadata">

**Author:** ![Aaron\_L](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@Aaron\_L](https://community.dynatrace.com/u/Aaron_L)\
**Post date:** [April 4, 2025, 2:40pm UTC](https://community.dynatrace.com/t/calculation-of-percentage-of-problems-with-summarize-in-dql/46382/3 "2025-04-04T14:40:50Z")

</div>

Hi Kris,

We are trying to do a similar thing, only using Log data.&nbsp; From a query cost perspective, would the summarize and expand option be “cheaper”, as we don’t have to run a subquery?

Thanks,  
Aaron

---

<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:** [May 4, 2026, 11:58am UTC](https://community.dynatrace.com/t/calculation-of-percentage-of-problems-with-summarize-in-dql/46382/4 "2026-05-04T11:58:48Z")

</div>

Yes!
