Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping by Day and Month, not the year

Status
Not open for further replies.

Woodyuk

IS-IT--Management
Aug 22, 2003
59
GB
Im trying to write a report in Crystal reports verison 14.
Im basically trying to pull out sales but want to group by date, but not use the year, as i want to compare the same date for each year.

So for example i might enter a date on my report of 24th Nov 2015.
I would then want it to bring back that date and the last 5 years, 24/11/14,24/11/2013 etc

I would also like it to bring back 7 days after that as well, (eg 25th, 26th, 27th, 28th,29th 30th, 1st Dec) and for years 2015,2014,2013, 2012 and 2011

I was hoping to do a parameter, where a user could enter a date for any time. This would return that date or dates, for the year speicfied and the last 5 years for example as well.


 
If I understand correctly, you want to bring back the parameter date, plus 7 days, and repeat the same 7 days for each of the previous 5 years.

Here is my solution:

//Current year 7 days
({TABLE.DATEFIELD} in {?DATE Parameter} to {?Date Parameter}+7)
or

//This bit is the YEAR-1 section
(
{TABLE.DATEFIELD} in
date( year({?Date Parameter})-1, Month({?Date Parameter}), Day({?Date Parameter}) )
to
date( year({?Date Parameter}+7)-1, Month({?Date Parameter}+7), Day({?Date Parameter}+7) )
)

Basically, the first section is your standard 7 day range, for the date paramter the user entered.
The second section shows the same information for the previous year Year({?Date Parameter})-1

Repeat the second section for each year you want, replacing the "-1" with "-2", "-3" etc.

I'm sure someone else has a more concise way of doing this, :-D

Also, adding the "+7" after the Date Parameter for Month and Day, allows for the user to select a date, say 30th October, and still get the next 7 days, of a previous year, without getting that error message about too many days in a month....
 
another option.. untested and hoping i got all my ()'s correct
Code:
{TABLE.DATEFIELD} in {?DATE Parameter} to dateadd('d',7,{?DATE Parameter}
or
{TABLE.DATEFIELD} in dateadd('yyyy',1,{?DATE Parameter}) to dateadd('yyyy',1,dateadd('d',7,{?DATE Parameter})
or
{TABLE.DATEFIELD} in dateadd('yyyy',2,{?DATE Parameter}) to dateadd('yyyy',2,dateadd('d',7,{?DATE Parameter})
or
{TABLE.DATEFIELD} in dateadd('yyyy',3,{?DATE Parameter}) to dateadd('yyyy',2,dateadd('d',7,{?DATE Parameter})
or
{TABLE.DATEFIELD} in dateadd('yyyy',4,{?DATE Parameter}) to dateadd('yyyy',2,dateadd('d',7,{?DATE Parameter})
or
{TABLE.DATEFIELD} in dateadd('yyyy',5,{?DATE Parameter}) to dateadd('yyyy',2,dateadd('d',7,{?DATE Parameter})

_____________________________________
Crystal Reports 2011 and XI
Intersystems Cache 2012 ODBC connection

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top