Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: Date Calculation Post Reply Post New Topic
Author Message
Kathleen
Newbie
Newbie
Avatar

Joined: 31 Dec 2007
Location: United States
Online Status: Offline
Posts: 17
Quote Kathleen Replybullet Topic: Date Calculation
    Posted: 11 Jan 2008 at 11:32am
Hello, Newbie again....
 
I am creating a report where I have to calculate whether or not a support function is being done every week.  The function does not have to be done on the same day every week and that's what causing my problems.
 
I've tried to use the DateDiff feature, but cannot get anything to calculate correctly.  
 
For instance, depth of pool water.  Inspections of the depth are to be done on a weekly basis.  Date is entered into Casper as DateCk.  I need to make sure that DateCk is being done weekly.
 
How do I create a calculation to do this?
IP IP Logged
Lugh
Senior Member
Senior Member
Avatar

Joined: 14 Nov 2007
Online Status: Offline
Posts: 377
Quote Lugh Replybullet Posted: 14 Jan 2008 at 5:39am
First, let's clarify what you mean by "weekly."  Do you mean that no two inspections can be more than 7 days apart?  Or, simply that there must be at least one inspection during every calendar week?  Because, these require two very different solutions.

The first one is actually the easier one.  Create a formula for each record that looks like:

If DateDiff("d",Previous({MyReport.DateCk}),{MyReport.DateCk}) > 7 Then
    "Late Inspection"
Else
    "Within Parameters"

Obviously, you should probably change the actual output.  Making this something like a condition to change the Date to red when it's late might be good.


The second one is trickier.  That's because there is no built-in function in Crystal to find a missing week.  There are a few options.

One is to do something like the above, but test it based on the week rather than the number of days between.  It might look like:

If DatePart("ww",{MyReport.DateCk}) - DatePart("ww",Previous({MyReport.Date)) > 1 Then
    "Late Inspection"
Else
    "Within Parameters"

However, all this does is flag the late inspections.  It doesn't necessarily tell you the missing dates.  (Also note that it fails on the first week of the year, but it's fairly trivial to add an extra bit to account for that.)

Another option is to add a table to your database, which includes the date of each Sunday for the year.  Or, probably, a more generic table of sequential numbers, which you use to calculate the date for each Sunday of the year.  Then, create a join between this table and your inspection table, and make a note of any Sunday that doesn't have a corresponding inspection in the next 7 days.


IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.094 seconds.