Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Need help on Date Range formula Post Reply Post New Topic
Author Message
mr_ding
Newbie
Newbie


Joined: 02 Mar 2011
Online Status: Offline
Posts: 2
Quote mr_ding Replybullet Topic: Need help on Date Range formula
     Posted: 02 Mar 2011 at 6:22am
Hi,

I'm a newbie on Crystal Report, I am trying to convert some Excel file into .rpt and trying to write a formula which does the following:

Submit_Date
7/4/2009
9/30/2009
3/23/2010
...
3/2/2011

I want to group the SubmitDate into (0-4wks, 4-12wks, 12-52wks, > 52wks)

In Excel, I was using formula
=SUMPRODUCT((SubmitDate<TODAY()+1)*(SubmitDate>=TODAY()-28))
=SUMPRODUCT((SubmitDate<TODAY()-28)*(SubmiteDate>=TODAY()-96))
=SUMPRODUCT((SubmitDate<TODAY()-96)*(SubmitDate>=TODAY()-365))


I think the formula is something like:
if isnull({CQConverted_.Submit_Date})
   then '>52wks'  
   else if {CQConverted_.Submit_Date} < today & >= today-28
      then '0-4wks'
   else if {CQConverted_.Submit_Date} < today-29 & >= today-96
      then '4-12wks'
   else if {CQConverted_.Submit_Date} < today-97 & >=today-365
      then '12-52wks'
   else if {CQConverted_.Submit_Date} <today-366
      then '>52wks'
   else {CQConverted_.Submit_Date}

But I just do not know the exact format on how to accomplish (< today & > today-28).  Can someone please help me?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 Mar 2011 at 6:42am
Maybe...?
if isnull({CQConverted_.Submit_Date})
   then '>52wks'  
   else if datediff('d',{CQConverted_.Submit_Date},currentdate)<=28
      then '0-4wks'
   else if datediff('d',{CQConverted_.Submit_Date},currentdate)<=96
      then '4-12wks'
   else if datediff('d',{CQConverted_.Submit_Date},currentdate)<=365
      then '12-52wks'
   else if datediff('d',{CQConverted_.Submit_Date},currentdate)>366
      then '>52wks'
   else 'Not identified'
IP IP Logged
mr_ding
Newbie
Newbie


Joined: 02 Mar 2011
Online Status: Offline
Posts: 2
Quote mr_ding Replybullet Posted: 02 Mar 2011 at 7:54am
Thank you very much, works like a charm!
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