Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Record Formula Post Reply Post New Topic
Author Message
Ashman
Newbie
Newbie
Avatar

Joined: 12 Oct 2009
Location: Australia
Online Status: Offline
Posts: 3
Quote Ashman Replybullet Topic: Record Formula
     Posted: 12 Oct 2009 at 10:25pm
Hi All

Struggling with a record formula. I need to return all records from a previous time period (4 weeks prior to the ?From Date) including the current time period as well if there are records in a current time period.

EG

Company    Current Period   Previous Period
Test1           0                 10
Test2           1                 10
Test3           0                 10

I need to return only "Test2" because "Test1" & "Test3" does not have any current period data.

I should see only

Company    Current Period   Previous Period
Test2           1                 10


My record select statement currently looks like

{@StartDate} >= ({?From Date} - 27) and
{@StartDate} <= {?To Date}

If I put an If statement in it will only return the "Current Period" but not the "Previous Period":

If {@StartDate} in {?From Date} to {?To Date} then
{@StartDate} >= ({?From Date} - 27) and
{@StartDate} <= {?To Date}

FYI
{@StartDate} = Date({datetimefield})

I need to do it this way as I am running a chart and cross tab.

Hope this makes sense.



Edited by Ashman - 12 Oct 2009 at 10:26pm
Cheers, Ash
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 13 Oct 2009 at 6:15am
have you tried dateadd() instead of just subtracting?  I would think that subtracting would work, but if you are having problems try dateadd.  In addition, why not startdate in (fromDate -27) and toDate?
 
just wondering.
IP IP Logged
Ashman
Newbie
Newbie
Avatar

Joined: 12 Oct 2009
Location: Australia
Online Status: Offline
Posts: 3
Quote Ashman Replybullet Posted: 13 Oct 2009 at 3:21pm
Thanks Lock, no go im afraid with the dateadd, it does the same thing. Im thinking maybe I need to return all values and filter at group level perhaps (i have group level for the period - either current or last 4 weeks and company).
Cheers, Ash
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 14 Oct 2009 at 6:22am

If {@StartDate} in {?From Date} to {?To Date} then
{@StartDate} >= ({?From Date} - 27) and
{@StartDate} <= {?To Date}

doesn't work, as @startDate is in the range, but NEVER -27 days

 
I am assuming that the is a filter and that you entered it Report/Selection Formulas/Record.
 
would have thought that DATE(table.field) IN ({?From Date} - 27) to {?To Date} would work.
 
when this sort of issue occurs, I will create formulas that display the parts and the whole, like ({?From Date} - 27), to see if it is giving the value that I think it should, and DATE(table.field) IN ({?From Date} - 27) to {?To Date}...  Sometimes, what I think the values are, aren't and then I can adjust my logic to work.
 
HTH
IP IP Logged
Ashman
Newbie
Newbie
Avatar

Joined: 12 Oct 2009
Location: Australia
Online Status: Offline
Posts: 3
Quote Ashman Replybullet Posted: 14 Oct 2009 at 3:31pm
Thanks again Lock,

I will give it a go - the DATE(table.field) IN ({?From Date} - 27) to {?To Date} does work, however it returns all records from activity from the past 4 weeks for all companies. Basically what I am after is, if a company has had activity within the date range then it will also return their activity for the past 4 weeks.

Cheers
Cheers, Ash
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 15 Oct 2009 at 6:12am
I would think that you need another filter that is based on activity, or a conditional suppression.
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