Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: PreviousValue question Post Reply Post New Topic
Author Message
JCrowhurst
Newbie
Newbie


Joined: 03 Feb 2009
Online Status: Offline
Posts: 3
Quote JCrowhurst Replybullet Topic: PreviousValue question
     Posted: 04 Feb 2009 at 11:42am
Okay... a bit of a story here but I think knowing the full background will help... I've been asked to generate a report that shows the estimated and actual setup and run times for a number of machines. The SQL generated By CrystalReports to access the data is this:

SELECT "order_details"."order_id", "order_details"."order_line_nbr", "order_details"."docket_id", "track"."process_nme", "order_details"."order_qty", "order_routing"."setup_time", "order_routing"."run_speed", "track"."process_qty", "track"."start_date", "track"."setup_min", "track"."run_min"
 FROM   ("oboe_data"."dbo"."order_details" "order_details" INNER JOIN "oboe_data"."dbo"."order_routing" "order_routing" ON ("order_details"."order_id"="order_routing"."order_id") AND ("order_details"."order_line_nbr"="order_routing"."order_line_nbr")) INNER JOIN "oboe_data"."dbo"."track" "track" ON (("order_details"."order_id"="track"."order_id") AND ("order_details"."order_line_nbr"="track"."order_line_nbr")) AND ("order_routing"."process_id"="track"."process_id")
 ORDER BY "track"."process_nme", "track"."start_date"

The resultant report is done in CrysRep grouped by process_nme and sorted within the group by start-date. Works fine... except if a given order is listed more than once in the group (due to the job spilling over shifts for instance) it will list the estimated setup time each time in the report. See below for a snippet which illustrates this.

OrderID start_date Dock # Order_Qty Est Setup
STITCHER



56400-45 2/2/09 7:09 AM 126259 500 10
56800-00 2/2/09 8:27 AM 105442 1,000 10
56573-40 2/2/09 9:50 AM 135056 3,000 10
56744-10 2/2/09 12:27 PM 202680 80 10
56744-10 2/2/09 12:45 PM 202680 80 10
56035-10 2/2/09 1:18 PM 108971 450 10
58045-10 2/2/09 2:56 PM 108971 450 10
57095-20 2/2/09 2:57 PM 108971 450 10

As you can see in the example, 56744-10 is listed twice and has set-up times present for both; I'd rather it set this value to zero for all subsequent instances. What I thought to do (after reading a suggestion earlier in this forum) was to use PreviousValue to check to see if OrderID was the same as the line above.  So I used this for the formula called SetupCheck:

if {order_details.order_id} <> Previous({order_details.order_id}) then
    {order_routing.setup_time}
else
    0;

Problem fixed... except I now have two new problems which I'm now stuck on. The first is that it won't let me select formula in order to create a summary for the group based on the formula... I have checked and the result does seem to be a number.

The second problem is that for the very first line on the report, the value for SetupCheck is blank. Not zero, not the setup time value, it's blank. It shouldn't be.

Any ideas on what's going on and how I can get my report to come out as I want it to look?


Edited by JCrowhurst - 04 Feb 2009 at 11:43am
IP IP Logged
JCrowhurst
Newbie
Newbie


Joined: 03 Feb 2009
Online Status: Offline
Posts: 3
Quote JCrowhurst Replybullet Posted: 04 Feb 2009 at 1:47pm
Update: I've figured out why I couldn't summarize on the Formula... apparently Crystal Reports won't allow it period when the formula has Previous() in it.  :(

I've redone it as a running total with the Evaluate field set to this:

{order_details.order_id} <> Previous({order_details.order_id})

to force it to skip... and it largely works. Except for one glaring problem: the very first record is ignored, simply because there IS no previous record for it to compare to. So how do I work around this?
IP IP Logged
JCrowhurst
Newbie
Newbie


Joined: 03 Feb 2009
Online Status: Offline
Posts: 3
Quote JCrowhurst Replybullet Posted: 04 Feb 2009 at 1:55pm
Duh... figured it all out myself. Changed the Evaluate formula to:

OnFirstRecord or {order_details.order_id} <> Previous({order_details.order_id})

And it works...
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