# Calender-aware durations in DQL

**URL:** <https://community.dynatrace.com/t/calender-aware-durations-in-dql/43247>\
**Category:** DQL\
**Tags:** dql\
**Created:** [December 18, 2023, 9:43am UTC](https://community.dynatrace.com/t/calender-aware-durations-in-dql/43247 "2023-12-18T09:43:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![r\_weber](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/r_weber/32/24884_2.png) [@r\_weber](https://community.dynatrace.com/u/r_weber)\
**Post date:** [December 18, 2023, 9:43am UTC](https://community.dynatrace.com/t/calender-aware-durations-in-dql/43247/1 "2023-12-18T09:43:52Z")

</div>

Likely more an RFE than a question…

Currently DQL only supports duration types of “ns” to “d” ([here](https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/data-types#timeframe)).  
However especially with BizEvents you want to have something like calendar/week/month-aware durations and timeframes.  
E.g. I’m tracking orders and revenue. I want to create a report/dashboard that shows data of this month/last month, last six months, this week, previous week.  
I don’t see how this can be done right now?

---

<div class="post-metadata">

**Author:** ![sinisa\_zubic](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/sinisa_zubic/32/32498_2.png) [@sinisa\_zubic](https://community.dynatrace.com/u/sinisa_zubic)\
**Post date:** [December 18, 2023, 10:50am UTC](https://community.dynatrace.com/t/calender-aware-durations-in-dql/43247/2 "2023-12-18T10:50:29Z")

</div>

Hi&nbsp;[@r\_weber](https://community.dynatrace.com/user/35901)

Currently there is not an easy way of doing this

Revenue of this month

```markup
fetch bizevents, from: bin(now()-duration(getDayOfMonth(now())-1,unit:"d"),1d, at: -1h)
| summarize sum(amount)

```

revenue of last month

```markup
fetch bizevents, 
  from: totimestamp(if(formatTimestamp(now(), format:"M") == "1", 
  concat(getYear(now()) -1,"-12-01-01"), else: (concat(getYear(now()), "-",toLong(formatTimestamp(now(), format:"M"))-1, "-01-01")))),
  to: bin(now()-duration(getDayOfMonth(now())-1,unit:"d"),1d, at: -1h)
| summarize sum(amount)

```

revenue of this week

```markup
fetch bizevents, from: bin(now()-duration(getDayOfWeek(now())-1,unit:"d"),1d, at: -1h)
| summarize sum(amount)

```

revenue of last week

```markup
fetch bizevents, 
  from: toTimestamp(concat(getYear(now()-7d), "-01-01"))
    + duration((getWeekOfYear(now()-7d)-1)*7+1, "d"),
  to: bin(now()-duration(getDayOfWeek(now())-1,unit:"d"),1d, at: -1h)
| filter isNotNull(amount)
| summarize sum(amount)

```

revenue of last six month I think is also possible just with a more complex and nested usage of if function.

Best,  
Sini
