Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Data Retrieval Post Reply Post New Topic
Author Message
Frank in VA
Groupie
Groupie
Avatar

Joined: 15 Nov 2007
Location: United States
Online Status: Offline
Posts: 46
Quote Frank in VA Replybullet Topic: Data Retrieval
     Posted: 11 May 2009 at 8:15am
Hi All,
I have here what's turning out to be a very complicated issue for me.  When a user enters a parameter date, I need to collect data from the past 12 months.  For example, if the date entered is today, 05/11/2009, I need to grab all records with a start date of 06/01/2008 thru 05/01/2009.  Not a calendar year as in the 'LastYearYTD' function.  Can anyone help on this?
 
Thanks!
Frank


Edited by Frank in VA - 11 May 2009 at 8:17am
Frank
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 11 May 2009 at 11:19am
I am assuming you really wanted it to be bewteen 5-1-08 and 4-30-09 which would be the previous 12 months from a 5-11-09 parameter entry:
{table.datefield} in Dateadd("yyyy",-1,(dateadd("d",-(datepart("d",{?My Parameter}))+1,{?My Parameter}))) to dateadd("d",-(datepart("d",{?My Parameter})),{?My Parameter})
IP IP Logged
Frank in VA
Groupie
Groupie
Avatar

Joined: 15 Nov 2007
Location: United States
Online Status: Offline
Posts: 46
Quote Frank in VA Replybullet Posted: 11 May 2009 at 12:22pm
Thanks for taking the time to reply to my post.  It works great.  But I am trying to understand the syntax because I need a slight adjustment.  Since the date I used is 5-11-09, this date is outside of the date range your formula gives me (5/2008 thru 4/2009) by one month.  It needs to show the data from 6/2008 thru 5/2009.
 
If I am understanding the code correctly, you are adding a negative date (actually subtracting) from the {table.datefield}, but you're doing it in parts.  I have tried adjusting the formula but I haven't been able to change the date range.  How can I move the dates one month forward?
 
Thanks!  Frank
Frank
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 11 May 2009 at 12:52pm
Ok but you realize you would only be looking at 11 months of data if you do it that way. Your intital post was asking for the last 12 months of data from an user entered parameter. including 5-1-09 is only 1 day, not a full month.
The formula is in two parts to get your begin and end dates
part 2 (end date) uses the parameter field, extracts the day part (1-31) and subtracts that from the parameter date to give you the last day of the previous month of the parameter. I purposefully did not make it go to the first day of the current month because technically it should not be included in a 12 month analysis. If you want it to to be the first day of the month just add 1 to the day subtraction portion.
dateadd("d",-(datepart("d",{?My Parameter}))+1,{?My Parameter})
The other is a little trickier and I really don't think it is what you want... to go back 11 months instead of 1 year change it from subtracting 1 year to 11 months.
Dateadd("m",-11,(dateadd("d",-(datepart("d",{?My Parameter}))+1,{?My Parameter})))
This formula does a double date add. The inside part converts the parameter to the first day of the month and year of the parameter entered. This is the same code as the first part of your request.
The outside dateadd converts that date to 11 months prior (or 1 year prior in the original post)


Edited by DBlank - 11 May 2009 at 12:58pm
IP IP Logged
Frank in VA
Groupie
Groupie
Avatar

Joined: 15 Nov 2007
Location: United States
Online Status: Offline
Posts: 46
Quote Frank in VA Replybullet Posted: 12 May 2009 at 5:35am
This is working great!  Thanks for you help on this.  Frank
Frank
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