# Calculating a Rolling Summary in a DQL

**URL:** <https://community.dynatrace.com/t/calculating-a-rolling-summary-in-a-dql/41942>\
**Category:** DQL\
**Tags:** dql, logs\
**Created:** [October 5, 2023, 10:03am UTC](https://community.dynatrace.com/t/calculating-a-rolling-summary-in-a-dql/41942 "2023-10-05T10:03:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmurray30](https://avatars.discourse-cdn.com/v4/letter/p/7ba0ec/32.png) [@pmurray30](https://community.dynatrace.com/u/pmurray30)\
**Post date:** [October 5, 2023, 10:03am UTC](https://community.dynatrace.com/t/calculating-a-rolling-summary-in-a-dql/41942/1 "2023-10-05T10:03:00Z")

</div>

Hello,

I have the following DQL, which returns a time series of a metric “incoming count in last minute” from a custom extension/generic db query.

_timeseries query=sum(custom.db.query), :interval:1m,_  
_filter:{in(dt.entity.custom\_device,classicEntitySelector(“type(custom\_device),entityName.equals(\“Incoming count in last 1 mins\”)”))},_  
_by:{dt.entity.custom\_device}_

What I’m after is for every minute, return the incoming count for the last 60 minutes, i.e. calculating the total count for the last 60 minutes, every minute.

I could define a db query and another metric to calculate this, but currently we’re having performance/capacity issues so really don’t want to add another custom db query when I should be able to derive the answer.

P.S. bins or increasing the interval, doesn’t give me the granularity I need to compare against existing charts.

Thanks

---

<div class="post-metadata">

**Author:** ![ChadTurner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/chadturner/32/161_2.png) [@ChadTurner](https://community.dynatrace.com/u/ChadTurner)\
**Post date:** [November 14, 2024, 12:57pm UTC](https://community.dynatrace.com/t/calculating-a-rolling-summary-in-a-dql/41942/2 "2024-11-14T12:57:11Z")

</div>

[@pmurray30](https://community.dynatrace.com/user/67453)&nbsp;- were you able to get a query for this, or a solution?

---

<div class="post-metadata">

**Author:** ![pmurray30](https://avatars.discourse-cdn.com/v4/letter/p/7ba0ec/32.png) [@pmurray30](https://community.dynatrace.com/u/pmurray30)\
**Post date:** [November 14, 2024, 5:51pm UTC](https://community.dynatrace.com/t/calculating-a-rolling-summary-in-a-dql/41942/3 "2024-11-14T17:51:31Z")

</div>

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

At the time no, but after a year more of experience, it took me a couple of hours to come up with this.

```markup
timeseries {QueryRslt=Max(custom.db.query), timestamp=start()}, by: { dt.entity.custom_device } , 
  interval:1m, 
  filter: { in(dt.entity.custom_device, 
  classicEntitySelector("type(custom_device),entityName.equals(\"Incremental Count\")")) }
| fieldsAdd key = tolong(timestamp[]-arrayFirst(timestamp))/1000000000
| join on:{key} , 
  [timeseries {QueryRslt=Max(custom.db.query), timestamp=start()}, by: { dt.entity.custom_device }, 
    interval:1m, shift:-10m, 
    filter: { in(dt.entity.custom_device, 
    classicEntitySelector("type(custom_device),entityName.equals(\"Incremental Count\")")) }
  | fieldsAdd key = tolong(timestamp[]-arrayFirst(timestamp))/1000000000] 
| fieldsAdd delta=QueryRslt[]-right.QueryRslt[]
| fields timeframe, interval, delta

```

This works with a incremental count, but should be able to be adapted to a minute reading if you have more joins and add the readings.

Maybe there is a cleaner way of doing it, but at the time I ended up just adding another custom query.
