# How to Aggregate (Sum) Success vs Failure Counts Totals per Time Interval in DQL

**URL:** <https://community.dynatrace.com/t/how-to-aggregate-sum-success-vs-failure-counts-totals-per-time-interval-in-dql/53563>\
**Category:** DQL\
**Tags:** dql, dynatrace-managed, notebooks\
**Created:** [September 30, 2025, 4:01am UTC](https://community.dynatrace.com/t/how-to-aggregate-sum-success-vs-failure-counts-totals-per-time-interval-in-dql/53563 "2025-09-30T04:01:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raul\_rrr](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@Raul\_rrr](https://community.dynatrace.com/u/Raul_rrr)\
**Post date:** [September 30, 2025, 4:01am UTC](https://community.dynatrace.com/t/how-to-aggregate-sum-success-vs-failure-counts-totals-per-time-interval-in-dql/53563/1 "2025-09-30T04:01:47Z")

</div>

We are trying to build a metric to monitor the success vs failure rate of an API over time.

**Requirement:**

- Treat all status codes between 400–599 as Failure
- Treat all other status codes as Success
- Display this in a bar/line chart with\*\*:\*\*
  - **X-Axis:** Timeframe
  - **Y-Axis:** Count of Success and Failure

- Created a Custom Metric which Captures Endpoint Name and Client ID used for Dashboard Filtering.

**Issue:**  
Using the below DQL, we are able to generate the data. However, the output splits into multiple Success and Failure counts. For example, within a 5-minute interval, each unique combination of endpoint, client, service, and status is treated as a separate record.

Our expectation is to see only two records per timeframe (Success and Failure totals), but instead we are getting multiple entries.

We attempted to use dedup status to consolidate the records, but this results in loss of data and incorrect counts.

Looking for an alternate approach that allows us to aggregate Success and Failure counts properly and visualize them as a bar/line graph.

“If we try to summarize success and failure, then Line Graph goes unsupported.”

```markup
timeseries {
  value = sum(service.muleapi.response.count)
},
by: {dt.entity.service, http.response.status_code},
filter: {
  in(endpoint.name, array($Endpoint)) AND in(`request_attribute.Client-Id`, array($Client_ID))
}
| lookup [
    data record(service_id = "SERVICE-EXXXFB", api_name = "ABC"),
    record(service_id = "SERVICE-9XXXX448", api_name = "DEF"),
    record(service_id = "SERVICE-FXXXX926", api_name ="XYZ")
  ], sourceField: dt.entity.service, lookupField: service_id
| fieldsAdd API = lookup.api_name
| fieldsRemove lookup.service_id, lookup.api_name
| filter in(API, array($API_Name))
| fieldsAdd status = if(condition: http.response.status_code >= 400 AND http.response.status_code < 600,
   then: "Failure", else: "Success" )
| sort status desc
//| dedup status

```

**Screenshots: Line Graph with geometry as bar graph**

Without dedup (with Legend) – multiple Success/Failure bars per timeframe

 ![Raul_rrr_0-1759204168782.png](https://global.discourse-cdn.com/dynatrace/original/2X/b/b92b1d2cbf050ee16b5d2b2565db22a593859d4d.png)

Without dedup (no Legend) – Graph looks fine visually, but bars still represent multiple records instead of aggregated totals

 ![Raul_rrr_3-1759204294119.png](https://global.discourse-cdn.com/dynatrace/original/2X/3/3e463e7a7e80b969c95db4780f72b42ed31098c1.png)

With dedup – Inaccurate data as multiple records are dropped

 ![Raul_rrr_2-1759204257435.png](https://global.discourse-cdn.com/dynatrace/original/2X/9/98557c0114d5bdb713a90d0c82816bb93310ec76.png)

Please suggest an alternate approach (without dedup) to&nbsp;&nbsp;aggregate Success vs Failure counts per timeframe, so that we only see two entries (Success, Failure) per interval?

---

<div class="post-metadata">

**Author:** ![dannemca](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/dannemca/32/7215_2.png) [@dannemca](https://community.dynatrace.com/u/dannemca)\
**Post date:** [September 30, 2025, 2:02pm UTC](https://community.dynatrace.com/t/how-to-aggregate-sum-success-vs-failure-counts-totals-per-time-interval-in-dql/53563/2 "2025-09-30T14:02:02Z")

</div>

Try to add a |maketimeseries sum(value), by:{status}

> **[DQL aggregation commands](https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/commands/aggregation-commands)**
>
> DQL aggregation commands

---

<div class="post-metadata">

**Author:** ![Raul\_rrr](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@Raul\_rrr](https://community.dynatrace.com/u/Raul_rrr)\
**Post date:** [October 7, 2025, 4:56am UTC](https://community.dynatrace.com/t/how-to-aggregate-sum-success-vs-failure-counts-totals-per-time-interval-in-dql/53563/3 "2025-10-07T04:56:07Z")

</div>

Hi&nbsp;[@dannemca](https://community.dynatrace.com/user/18264)&nbsp;,

Thanks for the suggestion! I tried adding&nbsp; | maketimeseries sum(value), by:{status}, but it’s still not working as expected. I’m getting the following error:  
“Please specify the parameter `time` explicitly, as the implicit default timestamp doesn’t exist.”

```markup
timeseries {
  value = sum(service.muleapi.response.count)
},
by: {dt.entity.service, http.response.status_code},
filter: { dt.entity.service == "SERVICE-A123" OR dt.entity.service == "SERVICE-B123" OR 
dt.entity.service == "SERVICE-C123"}
| fieldsAdd status = if(condition: http.response.status_code >= 400 AND http.response.status_code < 600,
   then: "Failure", else: "Success" )
| maketimeseries sum(value), by:{status}

```

Tried adding a time column and feeding it to makeTimeseries, but it fails: | fieldsAdd time = bin(interval, 1m) then | makeTimeseries sum(value), by:{status}, time: time

Execution returns an INCOMPATIBLE\_DATA\_TYPES

Any suggestions or example snippets that extract/bucket a timestamp from an interval/timeframe and work with makeTimeseries would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![dannemca](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/dannemca/32/7215_2.png) [@dannemca](https://community.dynatrace.com/u/dannemca)\
**Post date:** [October 7, 2025, 1:40pm UTC](https://community.dynatrace.com/t/how-to-aggregate-sum-success-vs-failure-counts-totals-per-time-interval-in-dql/53563/4 "2025-10-07T13:40:25Z")

</div>

Replace the "| fieldsAdd time = bin(interval, 1m) " by “| fieldsadd time = timeframe[start]” and try again.

It should works now.

---

<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 8, 2025, 12:47pm UTC](https://community.dynatrace.com/t/how-to-aggregate-sum-success-vs-failure-counts-totals-per-time-interval-in-dql/53563/5 "2025-10-08T12:47:51Z")

</div>

you can aggregate timeseries using this syntax:

```markup
| summarize value=sum(value[]), by: {dt.entity.service, status, interval, timeframe}

```

full query based on your exampe above:

```markup
timeseries {
  value = sum(service.muleapi.response.count)
},
by: {dt.entity.service, http.response.status_code},
filter: { dt.entity.service == "SERVICE-A123" OR dt.entity.service == "SERVICE-B123" OR 
dt.entity.service == "SERVICE-C123"}
| fieldsAdd status = if(condition: http.response.status_code >= 400 AND http.response.status_code < 600,
   then: "Failure", else: "Success" )

| summarize value=sum(value[]), by: {dt.entity.service, status, interval, timeframe}

```

of couse if you de not need to have breakdown by service, just ommit it in _ **by:** _ clause

```markup
| summarize value=sum(value[]), by: {status, interval, timeframe}

```

---

<div class="post-metadata">

**Author:** ![Raul\_rrr](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@Raul\_rrr](https://community.dynatrace.com/u/Raul_rrr)\
**Post date:** [October 8, 2025, 1:34pm UTC](https://community.dynatrace.com/t/how-to-aggregate-sum-success-vs-failure-counts-totals-per-time-interval-in-dql/53563/6 "2025-10-08T13:34:43Z")

</div>

[@krzysztof\_hoja](https://community.dynatrace.com/user/25373)&nbsp; -&nbsp;| summarize value=sum(value[]), by: {status, interval, timeframe} , worked perfectly. Thank you. Much&nbsp;appreciated!!

[@dannemca](https://community.dynatrace.com/user/18264)&nbsp;- Thank you as well for the makeTimeseries suggestion, it was very helpful.
