Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Creating a date range in the prior year from TY Post Reply Post New Topic
Author Message
venham
Newbie
Newbie


Joined: 28 Sep 2011
Location: Canada
Online Status: Offline
Posts: 11
Quote venham Replybullet Topic: Creating a date range in the prior year from TY
     Posted: 28 Sep 2011 at 9:27am
Hello all and thanks in advance for your help. 
 
I am trying to write a report that contains a comparison of sales from a current year date range against the same period last year.
 
What is the best way to use the two input dates ie., start and end to get the prior year range?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 28 Sep 2011 at 10:05am
table.date in [yeartodate, lastyearytd]

Edited by DBlank - 28 Sep 2011 at 10:07am
IP IP Logged
venham
Newbie
Newbie


Joined: 28 Sep 2011
Location: Canada
Online Status: Offline
Posts: 11
Quote venham Replybullet Posted: 29 Sep 2011 at 4:38am
Thanks DBlank for the prompt reply but I'm not sure I understand.  I'm very new at this.
 
I want to compare a range that the user inputs against the same period last year.
 
User inputs two dates Date_1 and Date_2
 
For each of Date_1 and Date_2, I have used the following to define my last year's dates as Date_start_LY and Date_end_LY and get the correct results:
 
DateAdd( 'Y', -365, {?Date_2})
 
However, when I try to use the two dates to select records it fails.  Have I not used the date fields correctly in the following selection?
 
IF {SALES_ORDER_HEADERS.SYS_SHIPPING_DATE} in {Date_start_LY} to {Date_end_LY}
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 29 Sep 2011 at 5:09am
I misunderstood your request as year to date not params that a user inputs at run time.
in that case I would do this in the select expert:
{SALES_ORDER_HEADERS.SYS_SHIPPING_DATE} in {?Date_1}  to {?Date_2}
or
{SALES_ORDER_HEADERS.SYS_SHIPPING_DATE} in dateadd('yyyy',-1,{?Date_1})  to dateadd('yyyy',-1,{?Date_2})
IP IP Logged
venham
Newbie
Newbie


Joined: 28 Sep 2011
Location: Canada
Online Status: Offline
Posts: 11
Quote venham Replybullet Posted: 29 Sep 2011 at 5:37am
Thank you very much!  That works perfectly.
 
Cheers!
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