# Aggregation of data from custom metric

**URL:** <https://community.dynatrace.com/t/aggregation-of-data-from-custom-metric/51552>\
**Category:** DQL\
**Tags:** dql, aggregations, timeseries\
**Created:** [May 9, 2025, 11:07am UTC](https://community.dynatrace.com/t/aggregation-of-data-from-custom-metric/51552 "2025-05-09T11:07:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andykrk](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@andykrk](https://community.dynatrace.com/u/andykrk)\
**Post date:** [May 9, 2025, 11:07am UTC](https://community.dynatrace.com/t/aggregation-of-data-from-custom-metric/51552/1 "2025-05-09T11:07:30Z")

</div>

Hello,

I am currently working on a Dashboard element that requires me to show error data coming from custom AWS metric. Basic DQL query in the Notebook:

```markup
timeseries sum(`my_custom_aws_metric`),
  interval: 1d,
  from: "2025-05-05",
  by: {aws.account.id, app_name, db_name, table_name},
  filter: { matchesValue(aws.account.id, { “1234” })}
| fieldsAdd error_count = arraySum(`sum(\`my_custom_aws_metric\`)`) 
| fieldsKeep timeframe, app_name, db_name, table_name, aws.account.id, error_count
| filterOut error_count == 0

```

produces the following output:

 ![andykrk_0-1746788124121.png](https://global.discourse-cdn.com/dynatrace/original/2X/5/5edc3e93ef6f4f55d5c1ee310206a806e5f52e1f.png)

I am trying to breakdown the timeframe and aggregation into daily chunks. I have tested multiple ways like for example:

```markup
timeseries {
  error_count = sum(`my_custom_aws_metric`),  
  bucket_start = start(),           
  bucket_end = end()              
},
interval: 1d,
from: "2025-05-05",
to: "2025-05-07",                    
by: {
  aws.account.id,
  app_name,
  db_name,
  table_name
},
filter: { aws.account.id == "1234" }   
| expand error_count
| expand bucket_start
| expand bucket_end
| filter app_name == “some_app”
| filterOut error_count == 0 or isNull(error_count)
| fieldsRename
    start = bucket_start,
    end = bucket_end
| fieldsKeep start, end, error_count,
             aws.account.id, app_name, db_name, table_name
| sort start asc

```

but it produced overlapping time intervals (I guess because of multiple expand commands) and also presented total error count from the whole period for each line:

 ![andykrk_1-1746788543075.png](https://global.discourse-cdn.com/dynatrace/original/2X/b/bf6e28c8c0f3f0d687c6e501cc5a20ff6eaab9fc.png)

For reference we want error\_count = 9 for each of those start and end dates:  
05/05/2025 - 06/05/2025  
06/05/2025 - 07/05/2025  
(this can also be simply day date)

I have tried multiple other methods but in the end I get mostly the same problems. Some of the commands I wanted to use like expand datapoints or arrayZip were unfortunately throwing error.

Any suggestions how to break it down the needed way?

---

<div class="post-metadata">

**Author:** ![marco\_irmer](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marco_irmer/32/3038_2.png) [@marco\_irmer](https://community.dynatrace.com/u/marco_irmer)\
**Post date:** [May 12, 2025, 9:53pm UTC](https://community.dynatrace.com/t/aggregation-of-data-from-custom-metric/51552/2 "2025-05-12T21:53:35Z")

</div>

See if [this DQL snippet](https://community.dynatrace.com/post/270741) helps.

---

<div class="post-metadata">

**Author:** ![andykrk](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@andykrk](https://community.dynatrace.com/u/andykrk)\
**Post date:** [May 13, 2025, 11:17am UTC](https://community.dynatrace.com/t/aggregation-of-data-from-custom-metric/51552/3 "2025-05-13T11:17:18Z")

</div>

Thank you very much, Marco! After some adaptation, this solution works great for me.

---

<div class="post-metadata">

**Author:** ![andykrk](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@andykrk](https://community.dynatrace.com/u/andykrk)\
**Post date:** [May 15, 2025, 10:04am UTC](https://community.dynatrace.com/t/aggregation-of-data-from-custom-metric/51552/4 "2025-05-15T10:04:09Z")

</div>

[@marco\_irmer](https://community.dynatrace.com/user/19769)&nbsp;I have one additional question. Currently one of the apps that I have (there is couple dozens of them) is running 2 times a day so we are adding up errors within the interval. Is it possible to pick the latest occurrence within the interval in case there is more than one? I think the timestamp is not explicitly listed as part of the metric but perhaps when we get the metric the time is passed automatically.
