Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Date Range Help. Post Reply Post New Topic
<< Prev  Page  of 2
Author Message
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 20 Mar 2015 at 9:07am
what are the definitions of each of the 'buckets' using a generic param place holder?
ie.
bucket 1 = all records where table.datefield month and year = param month and year
bucket 2 = all records where year of param = table date field year and table date field month is <= param month
etc.
IP IP Logged
Stircrazy08
Newbie
Newbie
Avatar

Joined: 12 Nov 2014
Location: United States
Online Status: Offline
Posts: 34
Quote Stircrazy08 Replybullet Posted: 20 Mar 2015 at 9:20am
parameter entered is 2/28/2015

Bucket1 = should be all records for current month
Bucket2 = all records for same month/previous year

Bucket3 = all records for 2 years ago thru param entered
Bucket4 = all records for last year thru param entered
Bucket5 = all records for this year thru param entered

so from 1/1 - current eom(parameter) for the various years.


this is a sales report that shows all sales for current month to same period last year.

and then running sales for current year compared to last year and year before last same time periods.

Peter F
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 20 Mar 2015 at 10:51am
select criteria
table.date between dateserial(year(?param)-2,1,1) and dateserial(year(?param),month(?param)+1,1-1)
 
your buckets can use
//bucket 1
if datediff('m',table.datefield,?param)=0 then table.sales else 0
//bucket2
if datediff('m',table.datefield,?param)=13 then table.sales else 0
//bucket 3
all select records?
//bucket 4
if table.date in dateserial(year(?param)-1,1,1) to dateserial(year(?param)-1,month(?param)+1,1-1) then table.sales else 0
//bucket 5
if table.date in dateserial(year(?param),1,1) to dateserial(year(?param),month(?param)+1,1-1) then table.sales else 0
 
hopefully these give you enough to tweak what you need
 
IP IP Logged
Stircrazy08
Newbie
Newbie
Avatar

Joined: 12 Nov 2014
Location: United States
Online Status: Offline
Posts: 34
Quote Stircrazy08 Replybullet Posted: 23 Mar 2015 at 4:37am
DB -
thanks so much for your time!! the buckets are working.
can you tell me what the syntax for dateserial is?

if table.date in dateserial(year(?param),1,1) to dateserial(year(?param),month(?param)+1,1-1) then table.sales else 0

what does the +1,1-1 mean? what other things can they be, say i want to change a date to 12/31 of last year?


thanks again for your help!
Peter F
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 23 Mar 2015 at 4:58am
dateserial(year +/- value, month +/-value, day +/- value)
 
lets you add or subtract values, much like dateadd, to a date but you can add or subtract to the year,month and/or day in the same process.
This means that if you add 1 month to 12(december) it will move to Jan of the next year rather than crash as there is no month value of 13.
 
You can 'debug' by creating a formula to see what each of the dateserial() portions return
 
dateserial(year({?param}),1,1)
uses the year() function to get the year from the paramter date and the "1, 1" just sets the day and month to jan first so no matter whjat year the user enters into  the param you will get Jan 1 of that year. 
in this case date(year({?param}),1,1) would work just as well.
 
dateserial(year({?param}),month({?param})+1,1-1)
this gets the year from the param to set the year of the date,
then gets the month from the param and adds 1 month to it to move into the following month
the "1" sets the month day to 1 so now you have the first of the month that is following the parameter and the -1 subtracts one day from this date which gives you the last day of the month from the parameter entered


Edited by DBlank - 23 Mar 2015 at 4:59am
IP IP Logged
Stircrazy08
Newbie
Newbie
Avatar

Joined: 12 Nov 2014
Location: United States
Online Status: Offline
Posts: 34
Quote Stircrazy08 Replybullet Posted: 23 Mar 2015 at 5:06am
This helps alot. thanks again for taking the time to explain.
Peter F
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 23 Mar 2015 at 7:43am
be forwarned I have seen a few 'odd' (or different) results when using dateadd() as compared to dateserial() when it comes to leap year and that one extra day. Just make sure they give you results you want.
IP IP Logged
<< Prev  Page  of 2
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