Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Date Formulas Post Reply Post New Topic
Author Message
KMendels
Newbie
Newbie


Joined: 24 Feb 2012
Online Status: Offline
Posts: 14
Quote KMendels Replybullet Topic: Date Formulas
     Posted: 01 Mar 2012 at 10:23am
I have a report with the following columns:

Feb. 2011    Feb. 2010  FY2011   FY2010

The dates are taken from a prompt asking for the Thru date.  All those fields are derived from formulas.  I would like to create a formula that shows all the months for a given fiscal  year.  Plus keep the column for FY2011 and the column showing the previous FY.

I want it to look like this (assuming when I'm prompted, I will be choosing FY 2011 as the current FY):

Jul 2011  August 2011...Jun 2011  FY2011  FY2012

I have the code to create a column based on the current month but how what is the code for previous months?  FY's run 7.1.10 - 6.30.11 (that would be for FY 2011) so I'll also have to take into consideration the years will be changing at some point.
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 01 Mar 2012 at 11:19pm
dateadd("m",-1,{currentmonthfield})
 
The above would return 02-Feb-2012 (as today is 02-Mar-2012).
 
Changing the -1 to -2 would return 02-Jan-2012... etc.
 
Regards,
Ryan.
IP IP Logged
KMendels
Newbie
Newbie


Joined: 24 Feb 2012
Online Status: Offline
Posts: 14
Quote KMendels Replybullet Posted: 02 Mar 2012 at 4:29am
Thanks!  What does the "m" do?  Tell it to look at the month?
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 02 Mar 2012 at 4:33am

Got it in one! ;-)

IP IP Logged
KMendels
Newbie
Newbie


Joined: 24 Feb 2012
Online Status: Offline
Posts: 14
Quote KMendels Replybullet Posted: 02 Mar 2012 at 7:26am
In the detail section, I need to keep a total of how many rows are returned that fall within the time period.  So when I run the report, I am prompted for a "Thru" date and I would enter today's date.
 
The report (before I made the above changes) would have the columns
 
March 2012  March 2011  FY2011 FY2012
 
The code to pull back the number of rows for the current month is:
If {case_action.csa_date3} >= {@Date This Month Start} and
   {case_action.csa_date3} <= {@Date This Month Thru} Then
       1
Else
       0
 
I tried modifying the code to bring back rows for Feb 2011 and it looks like this:
If {@Month-1} >= dateadd ("m", -1, {@Start-1}) and
   {@Month-1} <= dateadd ("m", -1, {@Date Thru Param} ) Then
       1
Else
       0
 
But it is assigning a 1 to all the rows - not just the ones that were a month behind the current month.  What did I do wrong?
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 05 Mar 2012 at 4:12am

I can't say for certain as I'm not sure what exactly each field/formula represents, but I think you should still be applying logic based on the original date field. ie;

If {case_action.csa_date3} >= {@Month-1} and
   {case_action.csa_date3} <= {@Date Thru Param} Then
       1
Else
       0
 
I'm also thinking you may need to make another formula for @end-1 that deducts a month from @date thru param otherwise the above would place a 1 next everything in February and March rather than just February.
 
Regards,
Ryan.
 
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