Print Page | Close Window

Increment a number on max date

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=10422
Printed Date: 06 May 2024 at 2:58pm


Topic: Increment a number on max date
Posted By: keithrichards
Subject: Increment a number on max date
Date Posted: 03 Jul 2010 at 6:25pm

Hi all,

 

I have the follow script which increments by 1 each time a particular vehicle has been into the service department after the specified date. If the same vehicle has been in twice after this date I still only want to count it once. Hence I am trying to count the max date. At the moment my script counts each instance the vehicle has been in.

 
Not sure if I am using the correct logic construct, but the existing script below nearly gives me what I need.

 

Existing Script

 

WhilePrintingRecords;
NumberVar CountService;
NumberVar CountReport;
If maximum ({service_Date},{Vehicle_Number}) > Date (2010, 06, 07) then
(CountService := CountRO + 1;
CountReport := CountReport + 1)

 

A snapshot of the current result looks like the following,

 

Service Date            Vehicle Number                  Count Service

19.04.2010              6FPAAAJG517840                        1

11.06.2010              6FPAAAJG517840                        2

24.08.2010              ABC12345891111                         3

 

What I am trying to achieve

 

Service Date            Vehicle Number                  Count Service
19.04.2010              6FPAAAJG517840                        0
11.06.2010              6FPAAAJG517840                        1

24.08.2010              ABC12345891111                          2

 
Any assistance would be GREATLY appreciated.
 
Thanks KR



Replies:
Posted By: lockwelle
Date Posted: 06 Jul 2010 at 3:52am

WhilePrintingRecords;
NumberVar CountService;
NumberVar CountReport;
If maximum ({service_Date},{Vehicle_Number}) > Date (2010, 06, 07)  AND  maximum ({service_Date},{Vehicle_Number})  ={service_Date} then
(CountService := CountRO + 1;
CountReport := CountReport + 1)

 
HTH


Posted By: keithrichards
Date Posted: 06 Jul 2010 at 4:13pm
Thanks for your help,
 
Stretching the friendship on another note, I'm using the NthLargest function in the script below and it is not working properly.
 
If {RO_DATE}  in Date (2008, 08, 01) to Date (2009, 07, 31) then
NthLargest(1, {RO_DATE},{vehicle_VIN})
 
I am trying to select the highest date where the date falls into the specified date range. Eg based on the above script and the dates below, I would want it to throw out out 04/05/2009.
 
11/03/2008
04/11/2008
04/05/2009
24/11/2009
21/05/2010
 
Any suggestions would be appreciated.
 
Many thanks,
 
KR


Posted By: lockwelle
Date Posted: 07 Jul 2010 at 3:18am

Sorry, never used NthLargest...you want to select 4/5/09?  That is what the code would seem to do. 

sorry can't be of more help



Print Page | Close Window