Get opened and closed workitems per day
WITH Dates AS (<br> SELECT<br> EventDate = CONVERT(DATE,'09/01/2017')<br> UNION ALL SELECT<br> EventDate = DATEADD(DAY, 1, EventDate)<br> FROM<br> Dates<br> WHERE<br> EventDate < '10/31/2017'<br>) SELECT<br> EventDate<br>FROM<br> Dates OPTION (MAXRECURSION 100)
This gives me the following output
2017-09-01T00:00:00 |
2017-09-02T00:00:00 |
2017-09-03T00:00:00 |
... 2017-10-31T00:00:00 |
I now want to add SQL code to add a column counting the number of workitems that were created on that day, and a column indicating the number that were closed. I'm struggling with the syntax to get this output. Can anybody give me a pointer ?
Thanks, Stephane
Answers
I'm not sure that exact graph is possible with a widget. You may need two graphs one for Created and one for Completed.
The following may help, it returns data with a row for each work item and the month it was completed (you could tweak this to be day). Then create a SQL Chart widget with this query and group by Date.
If thats not right or you do need all on one graph, then a custom page would be required.
Geoff
Which gives me the table output I need:
This gives me a table like this:
When I use this query as input for a SQL Chart Widget using the Stacked Column type, grouped by Date and stacked by Action, I get the following output:
I'm not entirely satisfied, because I'd prefer a graph that shows the Opened and Closed not stacked but in separate columns. I suppose I'd suggest that as a feature request. Also I haven't found an elegant solution to show items that have been opened and closed the same day in both the New and Closed buckets, which is why I used the Processed bucket as a workaround.
I'm very new to all this, and the past few days I've learned there is some really cool stuff you can do, but the chart widget is still lacking some basic functionality that would make it so much more useful.
Stephane
Hello Stephane,
Would you be willing to share the SQL query you used to create the stacked chart above?
Thanks,
Brett
Of course, here it is. This only deals with incident requests (classid). The tierid selects only the support groups of the IT department, which is why I added those classid's in as well.
I did start to notice a few small misalignments with the actual numbers that I suspect are due to tickets that have been open for a very long time (over a year)
------------------------------------------------
WITH Dates AS ( SELECT EventDate = DATEADD(MONTH,-2,CONVERT(DATE,GETDATE())) UNION ALL SELECT EventDate = DATEADD(DAY, 1, EventDate) FROM Dates WHERE EventDate < CONVERT(DATE,GETDATE()))
SELECT EventDate [Date],
(SELECT COUNT(wi.id) FROM workitem wi
WHERE CONVERT(DATE,wi.created) <= EventDate AND wi.ClassId= 'A604B942-4C7B-2FB2-28DC-61DC6F465C68' AND
wi.tierid IN ('4f2aa56c-ea20-3111-601a-7c5a3c00b13a','c52cfd69-7557-66ab-cbec-9d5fca856150','c2ad2601-2fa5-08af-a018-6f3bf3be0723','7598539c-77f6-48f9-8a01-d2cc68a8623f','df3896f5-3145-0546-4d25-e485de6765af')) [Opened],
(SELECT COUNT(wi.id) FROM workitem wi
WHERE CONVERT(DATE,wi.closedDate) <= EventDate AND wi.ClassId = 'A604B942-4C7B-2FB2-28DC-61DC6F465C68' AND
wi.tierid IN ('4f2aa56c-ea20-3111-601a-7c5a3c00b13a','c52cfd69-7557-66ab-cbec-9d5fca856150','c2ad2601-2fa5-08af-a018-6f3bf3be0723','7598539c-77f6-48f9-8a01-d2cc68a8623f','df3896f5-3145-0546-4d25-e485de6765af')) [Closed],
(SELECT COUNT(wi.id) -
(SELECT COUNT(wi.id) FROM workitem wi
WHERE CONVERT(DATE,wi.closedDate) <= EventDate AND
wi.ClassId = 'A604B942-4C7B-2FB2-28DC-61DC6F465C68' AND
wi.tierid IN ('4f2aa56c-ea20-3111-601a-7c5a3c00b13a','c52cfd69-7557-66ab-cbec-9d5fca856150','c2ad2601-2fa5-08af-a018-6f3bf3be0723','7598539c-77f6-48f9-8a01-d2cc68a8623f','df3896f5-3145-0546-4d25-e485de6765af'))
FROM workitem wi
WHERE CONVERT(DATE,wi.created) <= EventDate AND wi.ClassId= 'A604B942-4C7B-2FB2-28DC-61DC6F465C68' AND
wi.tierid IN ('4f2aa56c-ea20-3111-601a-7c5a3c00b13a','c52cfd69-7557-66ab-cbec-9d5fca856150','c2ad2601-2fa5-08af-a018-6f3bf3be0723','7598539c-77f6-48f9-8a01-d2cc68a8623f','df3896f5-3145-0546-4d25-e485de6765af')) [Backlog] FROM Dates
Group By EventDate
OPTION (MAXRECURSION 500)
--------------------------------------------------------------------------
This is good enough for us, but I'm quite sure the performance could be optimized by a real dba. I had to move along and work on other priorities. If you find a better way, please let me know.
Stephane
So, to give a bit more context:
Opened is the incidents that were created today, but have not (yet) been closed.
Closed are the incidents that were created before today, and that have been closed today.
Backlog / Processed is the number of tickets that were created today and have been closed the same day
Stephane
Wait, I may have given you the SQL for the trend histogram
So the correct SQL for the bar chart is:
-------------------------------------------------------------
WITH Dates AS (SELECT EventDate = DATEADD(MONTH,-2,CONVERT(DATE,GETDATE())) UNION ALL SELECT EventDate = DATEADD(DAY, 1, EventDate) FROM Dates WHERE EventDate < CONVERT(DATE,GETDATE()))
SELECT FORMAT (EventDate, 'yyyy-MM-dd') [Date], CASE WHEN CONVERT(DATE, wi.closeddate) = EventDate AND CONVERT(DATE, wi.created) = EventDate THEN 'Processed'
WHEN CONVERT(DATE, wi.closeddate) = EventDate THEN 'Closed'
WHEN CONVERT(DATE, wi.created) = EventDate THEN 'New'
ELSE '' END AS [Action], wi.DisplayName [Workitem], wi.created [Opened], wi.closeddate [Closed]
FROM Dates
LEFT JOIN workitem wi ON (EventDate=CONVERT(DATE,wi.closeddate) OR EventDate=CONVERT(DATE,wi.created)) AND (wi.ClassId = 'A604B942-4C7B-2FB2-28DC-61DC6F465C68' OR wi.ClassId = '04B69835-6343-4DE2-4B19-6BE08C612989') AND wi.tierid IN ('4f2aa56c-ea20-3111-601a-7c5a3c00b13a','0b29d425-97c1-bf7e-37dc-aa35f28c68ba','c52cfd69-7557-66ab-cbec-9d5fca856150','0e16b089-65ef-592b-927e-b9cd20403487','52fa3b51-66d1-b307-e747-9b129516df15','c2ad2601-2fa5-08af-a018-6f3bf3be0723','1b1da19a-8f18-b135-24d0-a35a5a2f3f47','7598539c-77f6-48f9-8a01-d2cc68a8623f','dceb5efa-8989-5977-4c48-1518aeca5bf2','df3896f5-3145-0546-4d25-e485de6765af')
OPTION (MAXRECURSION 100)
-------------------------------------------------------------------------------
Take what you need,
Stephane
Both work great! Thank you very much, Stephane.
I'm having trouble making since of how to setup the SQL Chart Widget. Any guidance you'd be willing to pass along on that? Thanks!
Failed to mention, that the above is for your "trend histogram" query.
I've read similar post recently: https://cireson.com/blog/dashboards-300
It would be very cool if Cireson would implement all those nice graphs into default Dashboards/Analytics of future portal versions 😉
These are my settings: