# Count of Problem in each week by its category of the event type from last one month data

**URL:** <https://community.dynatrace.com/t/count-of-problem-in-each-week-by-its-category-of-the-event-type-from-last-one-month-data/41289>\
**Category:** DQL\
**Tags:** notebooks\
**Created:** [August 22, 2023, 11:16am UTC](https://community.dynatrace.com/t/count-of-problem-in-each-week-by-its-category-of-the-event-type-from-last-one-month-data/41289 "2023-08-22T11:16:24Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bhargav\_314](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@Bhargav\_314](https://community.dynatrace.com/u/Bhargav_314)\
**Post date:** [August 22, 2023, 11:16am UTC](https://community.dynatrace.com/t/count-of-problem-in-each-week-by-its-category-of-the-event-type-from-last-one-month-data/41289/1 "2023-08-22T11:16:24Z")

</div>

Count of Problem in each week by its category of the event type from last one month data. Its giving wrong data.

fetch events, from:-30d  
| filter event.kind == “DAVIS\_PROBLEM”

| fieldsAdd open\_ts = if(event.status == “ACTIVE” AND event.status\_transition == “UPDATED”,timestamp)  
| filter isNotNull(open\_ts)  
| summarize  
open = min(open\_ts),  
by:{display\_id, event.category, event.name }  
| summarize  
count=countDistinct(display\_id),  
by:{open}

| summarize count = count(), by: {`1week interval` = bin(open, 7d)}  
| sort count desc

---

<div class="post-metadata">

**Author:** ![LawrenceBarratt](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/lawrencebarratt/32/26634_2.png) [@LawrenceBarratt](https://community.dynatrace.com/u/LawrenceBarratt)\
**Post date:** [August 22, 2023, 2:31pm UTC](https://community.dynatrace.com/t/count-of-problem-in-each-week-by-its-category-of-the-event-type-from-last-one-month-data/41289/2 "2023-08-22T14:31:08Z")

</div>

Hi,

You won’t need most of the query, only this DQL.

```javascript
fetch events, from:-30d
| filter event.kind == "DAVIS_PROBLEM"
| summarize ProblemCount = countDistinct(display_id), by:{event.category, `1 week interval` = bin(timestamp, 7d)}
| sort ProblemCount desc

```

 ![LawrenceBarratt_3-1692714649162.png](https://global.discourse-cdn.com/dynatrace/original/2X/0/03e2029115af0e55b5d4c8e4baedbe5631d5b4bf.png)

---

<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:** [August 22, 2023, 3:46pm UTC](https://community.dynatrace.com/t/count-of-problem-in-each-week-by-its-category-of-the-event-type-from-last-one-month-data/41289/3 "2023-08-22T15:46:12Z")

</div>

Hi&nbsp;[@Bhargav\_314](https://community.dynatrace.com/user/63764)

There are actually 2 things to consider why there is a discrepancy between the “problem feed” screen and the result of your query.

1. We have recently added a field “dt.davis.is\_duplicate” - that one should flag if a [davis problem is a merged problem or not](https://community.dynatrace.com/post/116104). so you need to filter those out.

2. You don’t have to filter on the timestamp of the transition to identify when a problem was opened or closed, now you can use the event.start or event.end field.

I hope following query works for you.

```markup
fetch events, from:-30d
| filter event.kind == "DAVIS_PROBLEM" 
| sort timestamp desc
| summarize {id = takeFirst(display_id), duplicate = takeFirst(dt.davis.is_duplicate), week = takeFirst(formatTimestamp(toTimestamp(toLong(event.start)), format:"w")), category = takeFirst(event.category)}, by:{display_id}
| filter duplicate == false
| summarize `Problem count` = count(), by:{`Week in year` = week, `Problem category` = category}

```

I can also share with you that the team is currently working on a new problem feed. There it will be possible that you pin e.g. the problem count on a dashboard or notebook. With that kind of action you will be also able to see how the DQL query behind the “problem count” number in the selected timeframe looks like. But I can’t give you an ETA for this.

Best,  
Sini

---

<div class="post-metadata">

**Author:** ![heybeckerj](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/heybeckerj/32/22189_2.png) [@heybeckerj](https://community.dynatrace.com/u/heybeckerj)\
**Post date:** [August 22, 2023, 4:48pm UTC](https://community.dynatrace.com/t/count-of-problem-in-each-week-by-its-category-of-the-event-type-from-last-one-month-data/41289/4 "2023-08-22T16:48:56Z")

</div>

[@sinisa\_zubic](https://community.dynatrace.com/user/38283)&nbsp;this is great!

Is there a way to group by more than 1 Category axis in the bar chart?

 ![heybeckerj_0-1692722926967.png](https://global.discourse-cdn.com/dynatrace/original/2X/5/5092b05170e29e2ef762284fe307337a1b088b09.png)

Right now you can only choose 1

---

<div class="post-metadata">

**Author:** ![Bhargav\_314](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@Bhargav\_314](https://community.dynatrace.com/u/Bhargav_314)\
**Post date:** [August 23, 2023, 5:05am UTC](https://community.dynatrace.com/t/count-of-problem-in-each-week-by-its-category-of-the-event-type-from-last-one-month-data/41289/5 "2023-08-23T05:05:04Z")

</div>

Hi&nbsp;[Lawrence,](https://community.dynatrace.com/user/47736)

Counts are not matching when i match the notebooks output with problems page. Can you please check once?

 ![Problems page.PNG](https://global.discourse-cdn.com/dynatrace/original/2X/9/9f386fc8e0e0c057c025e40dcb5d917693844471.png)  
 ![Notebooks page.PNG](https://global.discourse-cdn.com/dynatrace/original/3X/f/d/fd0b7965770a82fbdd33628ec5fe818be9371fea.png)

---

<div class="post-metadata">

**Author:** ![Bhargav\_314](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@Bhargav\_314](https://community.dynatrace.com/u/Bhargav_314)\
**Post date:** [August 23, 2023, 5:08am UTC](https://community.dynatrace.com/t/count-of-problem-in-each-week-by-its-category-of-the-event-type-from-last-one-month-data/41289/6 "2023-08-23T05:08:18Z")

</div>

Hi&nbsp;Sini,

Instead of the week in year can I get the start date of the week.&nbsp; I was trying that but its failing. PFA screen shot for your reference.

Thanks,

Bhargav

 ![Note books screen shot.PNG](https://global.discourse-cdn.com/dynatrace/original/3X/4/2/4233f79cb037fed34044bd4525409834eb81d065.png)

---

<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:** [August 23, 2023, 6:07am UTC](https://community.dynatrace.com/t/count-of-problem-in-each-week-by-its-category-of-the-event-type-from-last-one-month-data/41289/7 "2023-08-23T06:07:41Z")

</div>

Hi&nbsp;Bhargav

that should be the query if you want to group by the start day of the week

```markup
fetch events, from:-30d
| filter event.kind == "DAVIS_PROBLEM" 
| sort timestamp desc
| summarize {id = takeFirst(display_id), duplicate = takeFirst(dt.davis.is_duplicate), open = takeFirst(toTimestamp(toLong(event.start))), category = takeFirst(event.category)}, by:{display_id}
| filter duplicate == false
| fieldsAdd weekOf=formatTimestamp(open-duration(getDayOfWeek(open) -1 ,"d"),format:"YYYY-MM-dd")
| summarize `Problem count` = count(), by:{weekOf, category}

```

Best,  
Sini

---

<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:** [August 23, 2023, 6:10am UTC](https://community.dynatrace.com/t/count-of-problem-in-each-week-by-its-category-of-the-event-type-from-last-one-month-data/41289/8 "2023-08-23T06:10:27Z")

</div>

Hi&nbsp;[@heybeckerj](https://community.dynatrace.com/user/46908)

Not sure when this will be possible. maybe&nbsp;[@Philipp\_Kastner](https://community.dynatrace.com/user/38485)&nbsp;can answer this?

Best,  
Sini

---

<div class="post-metadata">

**Author:** ![Bhargav\_314](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@Bhargav\_314](https://community.dynatrace.com/u/Bhargav_314)\
**Post date:** [August 23, 2023, 6:13am UTC](https://community.dynatrace.com/t/count-of-problem-in-each-week-by-its-category-of-the-event-type-from-last-one-month-data/41289/9 "2023-08-23T06:13:02Z")

</div>

Hi Sini,

Thanks for sharing the query, there is one issue i have found, we are fetching the data from last 30 days, but results are having June month data also. Can you please check once? I have attached screen shot.

 ![Note book Query wrong output.PNG](https://global.discourse-cdn.com/dynatrace/original/3X/f/f/ffe08f9ddd2ed81a3012107de4943fed0cb0c322.png)

---

<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:** [August 23, 2023, 6:53am UTC](https://community.dynatrace.com/t/count-of-problem-in-each-week-by-its-category-of-the-event-type-from-last-one-month-data/41289/10 "2023-08-23T06:53:13Z")

</div>

Hi&nbsp;Bhargav,

My assumption was that in your environment the problems do not last longer than 1 week. You must have problems which have started quite some while ago. So that query does not work pretty well if you have such kind of problems since I am grouping by event start date.

If you group by the timestamp (update time of the event), then the result should look better

```markup
fetch events, from:-30d
| filter event.kind == "DAVIS_PROBLEM" 
| sort timestamp desc
| fieldsAdd weekOf=formatTimestamp(timestamp-duration(getDayOfWeek(timestamp) -1 ,"d"),format:"YYYY-MM-dd")
| summarize {id = takeFirst(display_id), duplicate = takeFirst(dt.davis.is_duplicate), category = takeFirst(event.category)}, by:{display_id,weekOf}
| filter duplicate == false
| summarize `Problem count` = count(), by:{weekOf,category}

```

---

<div class="post-metadata">

**Author:** ![Bhargav\_314](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@Bhargav\_314](https://community.dynatrace.com/u/Bhargav_314)\
**Post date:** [August 23, 2023, 7:27am UTC](https://community.dynatrace.com/t/count-of-problem-in-each-week-by-its-category-of-the-event-type-from-last-one-month-data/41289/11 "2023-08-23T07:27:49Z")

</div>

Hi Sini,

This query looks fine, but problem counts are not matching. can you please check once ?

 ![Problems page.PNG](https://global.discourse-cdn.com/dynatrace/original/2X/9/9f386fc8e0e0c057c025e40dcb5d917693844471.png)

---

<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:** [August 23, 2023, 4:17pm UTC](https://community.dynatrace.com/t/count-of-problem-in-each-week-by-its-category-of-the-event-type-from-last-one-month-data/41289/12 "2023-08-23T16:17:56Z")

</div>

Can you make sure for the timeframe to use from 00:00 to 23:59 on the problem screen so it matches the DQL query?

Please also note that davis problems in grail are per default stored for 35 days.

by how much (relative & absolute) are the counts not matching?

Beside that I don’t know what could be the issue. for me the query is working in an environment with a similar amount of problems

If this still does not give you the desired result,&nbsp;&nbsp;then please create a support ticket via&nbsp;[https://one.dynatrace.com/hc/en-us/requests](https://one.dynatrace.com/hc/en-us/requests)&nbsp;. Tech support will help you with this issue

 ![sinisa_zubic_1-1692807532243.png](https://global.discourse-cdn.com/dynatrace/original/3X/c/4/c4e01a4ed830433c95b580c97c93f5795af3dde6.png)
