Reputation: 13
I am tasked with creating a report which counts open service tickets each day for the last 365 days. A ticket is classified as open for any given day if there is no completed date, or the completed date is greater than the day being evaluated and the created date is less than or equal to the day being evaluated. My problem is that I have no date field to group on in the report as I cannot group on the created or resolved date fields given that I am counting open tickets and potentially no ticket was created or completed on a given day.
I have tried creating a command which lists everyday and then adding it to the report with no join which of course creates a Cartesian product but this blows the report up and takes way to long to run. How can I create a group for each day for a given period (in this case the last 365 days) in which I can place my formula to count open tickets?
Is there a solution to this problem, any help greatly appreciated. I am using Crystal reports version 11.0.0.895
Upvotes: 0
Views: 258
Reputation: 799
This is a task you probably best solve in the database (or a query/command in Crystal Reports). As a sketch:
count
) of tickets that match your criteriaThis way you will have a resultset that always contains 365 rows, so there will be no problems in your report. Some of the rows may contain 0 if there are no tickets for that given day.
Below is an example. It uses a datetable. It shows two ways to get your ticket information to a given date:
Have a look at the where/join conditions (opened <= adate
and (closed is null or closed >= adate)
) whether they represent exactly what you want (should a ticket closed on date be counted as open for that day, will a ticket open and closed on the same date ever count as open, ....
create table #dates (adate date);
insert into #dates (adate) values
('2017-06-23'),
('2017-06-22'),
('2017-06-21'),
('2017-06-20'),
('2017-06-19')
create table #tickets (id int, opened date, closed date);
insert into #tickets (id, opened, closed) values
(1, '20170620', null),
(2, '20170620', '20170622'),
(3, '20170621', '20170622'),
(4, '20170624', null)
-- just the open tickets per day
select
adate
,(select count(id) from #tickets where opened <= adate and (closed is null or closed >= adate)) open_tickets
from #dates
left outer join #tickets on opened <= adate and (closed is null or closed >= adate)
-- tickets joined to date, all ticket information available
select
adate
,#tickets.*
from #dates
left outer join #tickets on opened <= adate and (closed is null or closed >= adate)
drop table #tickets
drop table #dates
Upvotes: 0