Print Page | Close Window

Open AND Closed status for Date Range

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=7378
Printed Date: 01 May 2024 at 10:27pm


Topic: Open AND Closed status for Date Range
Posted By: MBurnettt
Subject: Open AND Closed status for Date Range
Date Posted: 14 Aug 2009 at 7:15am
I have an existing report that I'm running for Date Range 7/27-7/31 and the problem I run into is that if a ticket was opened AND closed during the same period, only the "Closed" status of that ticket shows in the report.  There is nothing in my Select Expert that filters only "Active" or "Inactive" tickets, so the results should be any value.
 
I thought maybe it was my Join in the Database Expert that links my two tables, but it's currently set to Left Outer Join, chg.status <-chgstat.code, so it should return all results.
 
I'm using a {?DateRange} Parameter field. I have a formula but it isn't returning accurate results:
 
if {chg.ACTIVE_FLAG} = 1
then "Open"
else "Closed"
 
This shows a ticket that was closed on 7/30 but it doesn't appear in the results as being opened on 7/28.
 
I tried the following formula, but it still doesn't pull Open AND Closed status on the same ticket, and returns a True/False statement:
 
if {?DateRange}=PDMTimeToDateTime ({chg.open_date})
then {chgstat.sym}="Open"
else if {?DateRange}=PDMTimeToDateTime ({chg.close_date})
then {chgstat.sym}="Closed"
 
I know I'm close to finding an answer but it just isn't coming to me.  I know this can probably be done using a UNION, but how does that translate to an if/then statement? 
 
I'm on a deadline and need to figure this out before Monday.  I haven't found anything helpful in the forums and could really use some expert advice.  Any assistance would be greatly appreciated.
 
Michael
 
 



Replies:
Posted By: DBlank
Date Posted: 14 Aug 2009 at 7:27am
I assume your close_date field is NULL when a ticket is still open.
If you used the close date as any filtering at all you need to address this.
I do not understand what you are trying to pull so what is your select statement now?


Posted By: MBurnettt
Date Posted: 14 Aug 2009 at 7:36am

I'm not filtering on closed date. 

I'm running a report for the Software Development Lifecycle, pulling all Dev, BA and QA categories within a certain Date Range:
 
mailto:%7b@OpenDate - {@OpenDate } = {?DateRange} and
{chgcat.sym} startswith ["BA", "Dev", "PMO", "QAA", "QAP.Other", "QAP.Performance Testing"]


Posted By: DBlank
Date Posted: 14 Aug 2009 at 8:37am

I am rereading this and need some clarity here.

Is the issue that the data is not coming into the report at all or you are having trouble grouping it properly? Meaning you are looking at a date and seeing what was opened and closed on that date?
Also be aware that just because you have a left outer join does not mean it is going to function that way. Your select statement can change it to an inner join.


Posted By: MBurnettt
Date Posted: 14 Aug 2009 at 8:48am
I want all tickets to show in a particular date range regardless of status.  I have a Change Order that only shows in the report as "Closed", even though it was opened during that same time period.  The chart should reflect all Opened, Closed, and New tickets during a Date Range.  Since I don't have a select statement that filters on status, I'm not sure why the report isn't showing both the Open or "Active" AND Closed or "Inactive" status on the same ticket.  I hope that makes sense. 
 
I've even tried changing the link for the table to either Inner or Left Join, and receive the same results. 
 
Is Crystal preventing a ticket from appearing more than once if the status is different, as though it's treating them with an OR statement?


Posted By: DBlank
Date Posted: 14 Aug 2009 at 9:03am

I am still unclear on your process here but your last statement has me worried and.

Are you grouping on a status based on a formula to determine if a field is Open or Closed?
If there is only one row for each instance it only appears once in the Group that it meets the first IF then condition for. It will not appear in both.
 
Is this what you are trying to do?


Posted By: MBurnettt
Date Posted: 14 Aug 2009 at 9:15am
No, I'm not grouping based on status.  The only grouping I'm doing is number of Change Orders by department, regardless of status.  Status is set to any value.
 
My last statement which had you worried was just conjecture.  Something is preventing me from seeing the ticket in question listed twice in the report, once in Open status and when it was Closed.  Obviously, if the ticket is only showing once in a "Closed" status even though it was opened during the same date range, then my report is showing inaccurate results.
 
I see nothing wrong in my select statements or in the Database Expert.  I was hoping someone may have thought of something I haven't considered yet.
 
Let me know if you require further clarification.  I appreciate your help.


Posted By: DBlank
Date Posted: 14 Aug 2009 at 9:37am

OK this one has me worried. Can you calrify this...

"My last statement which had you worried was just conjecture.  Something is preventing me from seeing the ticket in question listed twice in the report, once in Open status and when it was Closed.  Obviously, if the ticket is only showing once in a "Closed" status even though it was opened during the same date range, then my report is showing inaccurate results."
Most DB's are set up to continually update ONE row of data as it is updated from Creation to completion. There are often other tables that show the history and have multiple ros of data but the main table aways only has one row. Does your system create a new row in the table you are using everytime a record is changed? If so can you post some sample data of the data with all rows from creation to closure?


Posted By: MBurnettt
Date Posted: 14 Aug 2009 at 10:03am
I'm not sure I understand what you're saying.  My data source, called "chg", has the tables "open_date" and close_date.  A new row is written to the open_date table anytime a ticket is created.  The same is true for the close_date table anytime a ticket status is changed to "Closed"  I am pointing to both of those tables in the data source, so I should get both opened and closed status tickets during a specific date range. 
 
Should I even be concerned with status, or should I be looking at the active flag?
 
active=1 which is open
inactive=0 which is closed
 
Either way, I'm not filtering on status or whether a ticket is active or inactive.


Posted By: MBurnettt
Date Posted: 14 Aug 2009 at 10:07am
Here is the SQL Query of my report as it is so far:
 
 SELECT "chg"."chg_ref_num", "chg"."summary", "chg"."open_date", "ca_contact"."first_name", "ca_contact"."last_name", "ca_resource_department"."description", "ca_contact"."contact_uuid", "chgstat"."sym", "chgcat"."sym", "pri"."sym", "chg"."close_date", "chg"."active_flag"
 FROM   "mdb"."dbo"."ca_resource_department" "ca_resource_department" INNER JOIN (((("mdb"."dbo"."chg" "chg" INNER JOIN "mdb"."dbo"."chgcat" "chgcat" ON "chg"."category"="chgcat"."code") INNER JOIN "mdb"."dbo"."ca_contact" "ca_contact" ON "chg"."affected_contact"="ca_contact"."contact_uuid") INNER JOIN "mdb"."dbo"."pri" "pri" ON "chg"."priority"="pri"."enum") LEFT OUTER JOIN "mdb"."dbo"."chgstat" "chgstat" ON "chg"."status"="chgstat"."code") ON "ca_resource_department"."id"="ca_contact"."department"
 WHERE  ("chgcat"."sym" LIKE N'BA%' OR "chgcat"."sym" LIKE N'Dev%' OR "chgcat"."sym" LIKE N'PMO%' OR "chgcat"."sym" LIKE N'QAA%' OR "chgcat"."sym" LIKE N'QAP.Other%' OR "chgcat"."sym" LIKE N'QAP.Performance Testing%')
 ORDER BY "ca_resource_department"."description"


Posted By: DBlank
Date Posted: 14 Aug 2009 at 10:11am
Interesting. this helps clarify and most likely your culprit is the select statment... the " mailto:%7b@OpenDate - {@OpenDate } = {?DateRange}" is likely changing your Outer join into an inner join.
Get rid of that to test and see if you get the missing records you were expecting.


Posted By: MBurnettt
Date Posted: 14 Aug 2009 at 10:21am
If I remove that how am I supposed to use the {?DateRange} parameter to search during a specific timeframe?
 
I tested it by removing the select statement and it pulled all change orders, but it is still only showing either opened or closed status tickets.


Posted By: DBlank
Date Posted: 14 Aug 2009 at 10:34am
This was for testing only. Although I just read the SQL posted and see no mention of a Close_date table or an Open_Date table as you mentioned earlier. Onle the Chg Table with the an Open_Date and CLose_Date field.
Am I missing somehting here?


Posted By: MBurnettt
Date Posted: 14 Aug 2009 at 11:27am
No, you have it right, I just referred to them backwards earlier.  I point to both the open_date and close_date fields in the Chg table.


Posted By: DBlank
Date Posted: 14 Aug 2009 at 11:45am
OK. We are back to the issue then that there is only one row of data. It just has a Close Date or NULL in that field.
Hence you will see it only once in your report. You can still do overall counts of Open or Closed on these but no grouping.
I am trying to help another person with a similar problem.
http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=7351 - http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=7351
 
Does this seem like the same probelm you have?


Posted By: MBurnettt
Date Posted: 14 Aug 2009 at 11:56am
Which field are you reffering to?  The close_date field?  That's a number field, and when I browse the data it's pulling dates of tickets that fall within that DateRange.  I don't see Null.
 
I tried the formula you provided in the other post and it says it's missing a ")"
 
if isnull (Opened.week) then closed.week else opened.week
 
Should I do this where Opened.week = chg.open_date
and closed.week - chg.close_date?


Posted By: MBurnettt
Date Posted: 14 Aug 2009 at 12:03pm
These are the results of my report, exported into Excel:
 
Department
Department/Category
Change # Status Opened Date Closed Date
Customer Benefits 949 Closed 7/29/2009  2:48:34 PM 7/30/2009  11:51:19 AM
Customer Benefits 933 Cancelled 7/27/2009  1:02:25 PM 7/27/2009  1:38:49 PM
Executive Office 954 Closed 7/30/2009  11:13:05 AM 7/30/2009  2:24:18 PM
Finance 944 RFC 7/29/2009  12:51:23 PM
Human Resources 960 Closed 7/30/2009  12:19:09 PM 7/30/2009  2:28:30 PM
Information Systems 968 Closed 7/31/2009  11:01:29 AM 8/10/2009  2:00:37 PM
Information Systems 935 Open 7/27/2009  1:22:46 PM
Information Systems 940 Released 7/29/2009  9:14:36 AM
 
As you can see, ticket 954 was closed on 7/30/2009  2:24:18 PM, but the opened date is 7/30/2009  11:13:05 AM.  What formula would I need to use to get that ticket to show up twice?


Posted By: DBlank
Date Posted: 14 Aug 2009 at 12:08pm
You can't use a formula. You have to make the data get pulled in twice which is much trickier. read the entire post I gave you just a bit ago and it explains that more clearly.
I did not see anything about grouping for your needs.
Why do you need it to show up twice?


Posted By: MBurnettt
Date Posted: 14 Aug 2009 at 12:15pm
Because the intent of the report is to show all opened and closed tickets during a period of time.  We can't have one ticket that only shows as Closed when it was opened during that same date range, because it throws the numbers off.  There can't be a ticket that was closed without it being created.


Posted By: DBlank
Date Posted: 14 Aug 2009 at 12:46pm

change your select statement to be an OR (this works only for the entire erport not if you are goinmg to group on some other field in the report and look for sub totals on that group)...

Your select statement will be something like ...
(chg.opendate in start date to end date
OR
chn.close date in start date to End Date)
and {chgcat.sym} conditions here
 
Then conditionally count your records with formulas or Running Totals (your choice)
 
Open count formula
if table.opendate in startdate to enddate then 1 else 0
Sum this formula field fo get a total # of opened in range
Close count formula
if table.closedate in startdate to enddate then 1 else 0
Sum this formula field fo get a total # of closed in range
 
 
RTs will use a formual for Evaluate on as
table.open_date in startdate to enddate
table.end_date in startdate to enddate


Posted By: MBurnettt
Date Posted: 14 Aug 2009 at 1:00pm
What would be my conditions?  Anything in the Status table, i.e. Open, Closed, etc?


Posted By: DBlank
Date Posted: 14 Aug 2009 at 1:22pm

It is up to you but my guess is just use the dates. definately do not use the status as it is dynamic and only reflects the last update not any status it may have been in which is what you want.

Most likely your condition for Open is
did the Open_date fall in your paramter range (yes include, no exlcude) so  later this formual to make the fierlds be the real items from your report
 
if table.opendate in startdate to enddate then 1 else 0
 
Sum this formula field at ther report level fo get a total # of opened in range
 
Most likely your condition for Closed is
did the Close_date fall in your paramter range (yes include, no exlcude)
Close count formula
if table.closedate in startdate to enddate then 1 else 0
Sum this formula field fo get a total # of closed in range
 
 
Or is you want to use Running Totals (RTs) they can use a conditional inclusion. It evaluates to True or False. (If TRue include if False Exclude). This is placed in the Evaluate section of a RT under Use a formula (click onthe x-2 and palce in there)
You need 2 RTS. OPenCount and CloseCount
OpenCOunt
Field to summarize = chg_ref_num
Type of SUmmary=Count
Evaluate, select Use a FOrmual and add in
table.open_date in startdate to enddate (repalce with real field names)
Reset set to Never.
Place on report Footer.
repaet process for ClosedCount but change the formul to something like:
table.end_date in startdate to enddate


Posted By: MBurnettt
Date Posted: 14 Aug 2009 at 2:08pm

I keep having problems with the select statement:

{chg.open_date} in (2009,08,10) to (2009,08,14)
OR
{chg.close_date} in (2009,08,10) to (2009,08,14)
and {chgcat.sym}
 
I get a ")" is missing error.


Posted By: DBlank
Date Posted: 14 Aug 2009 at 2:17pm
you need parenthesis around the OR statement
(
{chg.open_date} in (2009,08,10) to (2009,08,14)
OR
{chg.close_date} in (2009,08,10) to (2009,08,14)
)
Not sure that you need the and {chgcat.sym} unless you need to filter by this for some reason.


Posted By: MBurnettt
Date Posted: 14 Aug 2009 at 2:40pm
I still get an error that states the following:
 
The ) is missing.
 
I'm not sure what else it could be.  I'll play with it some more.


Posted By: DBlank
Date Posted: 17 Aug 2009 at 7:38am
(
{chg.open_date} in Date(2009,08,10) to Date(2009,08,14)
OR
{chg.close_date} in Date(2009,08,10) to Date(2009,08,14)
)
and
{chgcat.sym} startswith ["BA", "Dev", "PMO", "QAA", "QAP.Other", "QAP.Performance Testing"]



Print Page | Close Window