Print Page | Close Window

Last Quarter Function

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=6286
Printed Date: 29 Apr 2024 at 1:14am


Topic: Last Quarter Function
Posted By: rio826
Subject: Last Quarter Function
Date Posted: 06 May 2009 at 1:07pm
I have a report that I need to hardcode the date range.  This report will be run by the user any date but it will give them the data included only on the previous quarter, EX:
 
1st quarter (1/1/09 - 3/31/09) can be printed any date before the 2nd quarter (4/1/09 - 6/30/09) the same with the other quarters.
 
I looked on the Predefined Date Range Constants on CR but I couldn't find a constant for Last Quarter. 
 
I found on the archives a formula this formula:

{Incident_Date} in dateserial(year(DateAdd ("q", -1, currentdate)), (datepart("q",DateAdd ("q", -1, currentdate))*3)-2,1) to
currentdate - day(currentdate), but when I include it on my report, the beginning date is OK but the ending date is not March 31st.

 
How can I modify this to formula to just provide me with the previous quarter no matter when the report is run.
 


-------------
AR



Replies:
Posted By: lockwelle
Date Posted: 07 May 2009 at 7:11am

OK, you are on a calendar year, way easier than some fiscal years.

Why not use something like:
 
if now in CDate(year(now), 1, 1) to CDate(year(now), 3,31) then
...
else
 if now in CDate(year(now), 4, 1) to CDate(year(now), 6,31) then
  ...
 
I don't know this for a filter or what, but this should work...when I tried the above formula, it just subtracted 3 months from the current date (probably, not what you wanted)
 
HTH


Posted By: DBlank
Date Posted: 07 May 2009 at 7:25am
I am sure there is a more elegant solution but this should also work:
 
if datepart("q",currentdate)=1 then
datepart("q",{table.date})=4
and datepart("yyyy",{table.date})=datepart("yyyy",dateadd("yyyy",-1,currentdate))
else
datepart("q",{table.date})=datepart("q",dateadd("q",-1,currentdate))
and datepart("yyyy",{table.date})=datepart("yyyy",currentdate)


Posted By: rio826
Date Posted: 07 May 2009 at 8:12am
I tried your suggestion and works like charm.  Thanks,

-------------
AR



Print Page | Close Window