# DQL Monthly Query for problems

**URL:** <https://community.dynatrace.com/t/dql-monthly-query-for-problems/50494>\
**Category:** DQL\
**Tags:** dql\
**Created:** [February 27, 2025, 7:41pm UTC](https://community.dynatrace.com/t/dql-monthly-query-for-problems/50494 "2025-02-27T19:41:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eyad](https://avatars.discourse-cdn.com/v4/letter/e/c57346/32.png) [@Eyad](https://community.dynatrace.com/u/Eyad)\
**Post date:** [February 27, 2025, 7:41pm UTC](https://community.dynatrace.com/t/dql-monthly-query-for-problems/50494/1 "2025-02-27T19:41:09Z")

</div>

hi all, i am trying to do&nbsp;Monthly Problem Count and ServiceNow Ticket Count Over the Last 4 Months in one tile.

fetch dt.davis.problems  
| summarize TotalProblemMonthly=count(), by:{Month = formatTimestamp(timestamp, format: “MM-yyyy”)}  
| join [fetch dt.davis.problems  
| filter matchesPhrase(labels.alerting\_profile,“ServiceNow”)  
| summarize ServiceNowTickets=count(), by:{Month = formatTimestamp(timestamp, format: “MM-yyyy”)}], on:{Month}

the result coming out not sorted i want to sort it based on a month, however if i use sort command will not use the year ad well which is a problem. look at the result image. any recommendation to fix the query to sort it?

 ![Screenshot 2025-02-27 144024.png](https://global.discourse-cdn.com/dynatrace/original/2X/1/17404ff4c5f29f98a5d93d9f2d314ba387144288.png)

---

<div class="post-metadata">

**Author:** ![StrangerThing](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/strangerthing/32/12182_2.png) [@StrangerThing](https://community.dynatrace.com/u/StrangerThing)\
**Post date:** [February 27, 2025, 8:01pm UTC](https://community.dynatrace.com/t/dql-monthly-query-for-problems/50494/2 "2025-02-27T20:01:47Z")

</div>

Try putting the year first, and you don’t need to do the join.

fetch dt.davis.problems  
| summarize TotalProblemMonthly=count(),  
ServiceNowTickets=countIf(matchesPhrase(labels.alerting\_profile, “ServiceNow”)),  
by:{Month = formatTimestamp(timestamp, format: “yyyy-MM”)}  
| sort Month desc

---

<div class="post-metadata">

**Author:** ![Eyad](https://avatars.discourse-cdn.com/v4/letter/e/c57346/32.png) [@Eyad](https://community.dynatrace.com/u/Eyad)\
**Post date:** [February 27, 2025, 8:15pm UTC](https://community.dynatrace.com/t/dql-monthly-query-for-problems/50494/3 "2025-02-27T20:15:29Z")

</div>

Perfect!, my other question. why it says line graph is unsuitable. if i want the results in graph.

---

<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:** [February 28, 2025, 8:18am UTC](https://community.dynatrace.com/t/dql-monthly-query-for-problems/50494/4 "2025-02-28T08:18:37Z")

</div>

You should use rounded timestamps, not string representation. Also to do proper bar chart it is better to use timerange so single bar spans the time it applies to:

```markup
fetch dt.davis.problems
| summarize { TotalProblemMonthly=count() , ServiceNowTickets=countIf(matchesPhrase(labels.alerting_profile, "ServiceNow")) },
  by:{ timeframe=timeframe( from: timestamp@M, to: timestamp@M+1M ) }
| sort timeframe desc

```

I used time alignment operators:&nbsp;[DQL operators — Dynatrace Docs](https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-query-language/operators#time-alignment).

Result look like this:

 ![krzysztof_hoja_0-1740729792108.png](https://global.discourse-cdn.com/dynatrace/original/1X/e05facd2e968593f51816755b732a053350b2eb4.png)

 ![krzysztof_hoja_1-1740730602967.png](https://global.discourse-cdn.com/dynatrace/original/3X/f/5/f5c6a387f43d7f92fac97b6b39690ee3096ed2cc.png)
