Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: formula to specify date ranges in a report Post Reply Post New Topic
Author Message
ejsjrnc
Newbie
Newbie


Joined: 26 Sep 2008
Online Status: Offline
Posts: 4
Quote ejsjrnc Replybullet Topic: formula to specify date ranges in a report
     Posted: 01 Oct 2008 at 6:53am
I need to create a formula based on a few different criteria.

I work in a helpdesk environment and we run weekly, monthly, quarterly and yearly reports on a variety of different datasets.

What I want to accomplish is this:
Create parameters in the report to specify the range of dates I want (ie weekly, monthly, quarterly or yearly), then based on the selection allow the user to select either a week#, month, quarter or year to run the data on.

I'm not sure exactly how to set up the logic in the formula for this.  I can do it for week, month and quarter individually, but I'm not 100% sure how to combine them all into 1 formula or if it would even be possible. 
IP IP Logged
JohnT
Groupie
Groupie
Avatar

Joined: 20 Jan 2008
Online Status: Offline
Posts: 92
Quote JohnT Replybullet Posted: 01 Oct 2008 at 8:28am
Will this always be current week, month etc or do you want to be able to run historical reports ?  The easiest way would be to ask the user to enter a  begin date and an end date and use that as your query. 
 
If you don't ask for a begin/end date as a parameter, you will probably end up querying a lot of records and using Crystal to only print the ones you want. 
 
You might search the help screen and look for Date Ranges.  There are numerous functions available (Calendar1stqtr, weektodatefromsun, monthtodate etc) that you might be able to use. 
 
Could you give a bit more detail of how you want this to work ?
 
 
IP IP Logged
ejsjrnc
Newbie
Newbie


Joined: 26 Sep 2008
Online Status: Offline
Posts: 4
Quote ejsjrnc Replybullet Posted: 01 Oct 2008 at 10:51am
I'll give an example of 1 way that I have the week specified.

Currently the reports prompt a user for a begin date and end date to query the data on. 

I was able to modify one of the reports that I only run weekly to prompt for a week number based on our corporate quarterly calender.
My parameters are set as follows:
WeekNum
SelectionYear (ie 2007, 2008, or 2009)

Formula:
Week1:
if {?SelectionYear} = 2007 then DateTime (2007,02,03) else
if {?SelectionYear} = 2008 then DateTime (2008,02,02) else
if {?SelectionYear} = 2009 then DateTime (2009,01,31)

CurWeekStart:
{@Week1} + (({?WeekNum}-1)*7)

CurWeekEnd:
{@CurWeekStart} + 7

Selection formula is:
{Submit_Date} in {@CurWeekStart} to {@CurWeekEnd}

When I refresh the data, it prompts me for the week number.

I'd like to program some logic into the report that will let me choose the date ranges as follows:
if weekly, pick week number
if monthly, pick month
if quarterly, pick quarter
if yearly, pick year

I'm not really sure how to do that unless I gather the data for the entire year every time I run the report and then display only the date range I want. 
This isn't really practical as there are typically anywhere from 12000 to 18000 records created monthly in the database tables I'm looking at.

edit: I've reviewed the built in calendar date functions, but since the year ranges I'm looking at are non-standard, I don't think they will work.


Edited by ejsjrnc - 01 Oct 2008 at 10:52am
IP IP Logged
JohnT
Groupie
Groupie
Avatar

Joined: 20 Jan 2008
Online Status: Offline
Posts: 92
Quote JohnT Replybullet Posted: 01 Oct 2008 at 12:11pm

This is an interesting problem.  I wonder if you could have 3 parameters. 

1.  Report type (1=weekly, 2=monthly etc)

2.  Sequence (a number to represent which week, or month or quarter etc)

3.  Year
 
You might have to edit the parameters to make sure someone didn't put month 14 or week 55.
 
if report type = 1
      calculate the begin and end date of the appropriate week in the year
           (I think you already have this)
else
      if report type = 2
          calculate the begin and end date of the appropriate month in
                  the year
      else
            if report type = 3
               calculate the begin and end date of the appropriate quarter in
                    the year
            else
                     etc.........................
 
The problem with this is that it might be a bit tricky to calculate the beginning and ending dates.  I think you already figured out how to do the weekly dates.  If you can calculate those, you can use the begin and end date in your query to select the records you want.  
 
Sorry I don't have an exact solution for you. 
    
 
IP IP Logged
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