|
|||||||||
|
Crystal Reports Tools: Improve Performance While Saving Time and Money |
|
Crystal Reports:
Often you need to select a
range of records from the report using a date range, so you would use a
record selection of:
|
|
Month List: This formula builds up a list of the names of the months: local numbervar y; //Counter for year loop local numbervar m; //Counter for month loop local numbervar m1; // 1st month for the month loop local numbervar m2; // final month for the month loop local stringvar s:=""; // Result string to print out at the end for y:= year({Orders.Order Date}) to year(next({Orders.Order Date})) do ( //for every missing year if y= year({Orders.Order Date}) then m1:=month({Orders.Order Date})+1 else m1:=1; if y= year(next({Orders.Order Date})) then m2:=month(next({Orders.Order Date}))-1 else m2:=12; if m1<=12 and m2>=1 then // Cannot be before January or after December for m:=m1 to m2 do ( s:=s + totext(date(y,m,1),"MMM-yyyy")+ chr(10) + chr(13)); //build the string ); s //print the result out
Sorry, this method is available only for CR version 8 users because it has For loops. Good luck.
How easy it would be to modify the formula above for missing days or missing weeks? The missing days formula is a lot easier to write as you are just looking for successive days. Missing Day: The first formula you need is to decide if days are missing: if {Orders.Order Date}+1 <> next({Orders.Order Date}) and {Customer.Customer ID}= next({Customer.Customer ID}) then {@Day List}
This formula is placed in a Group Footer Section by itself, and the section is formatted "Suppress Blank Section"
Day List: This formula builds up a list of the names of the months: local numbervar d; //Number of missing days local numbervar i; //Counter for loop local stringvar s:=""; //String to print out the result d:= next({Orders.Order Date})- {Orders.Order Date}-1; //Calculate the number of missing days for i:= 1 to d do ( s:=s + totext({Orders.Order Date}+ i,"dd-MMM-yyyy")+ chr(10) + chr(13)); s
Missing weeks is a little bit more complicated. You first need a formula to calculate the start of each week: Start of Week: {Orders.Order Date}-DayOfWeek ({Orders.Order Date})+1 Then your Missing Weeks formula is as follows: if {@Start of Week}+7 <> next({@Start of Week}) and {Customer.Customer ID}= next({Customer.Customer ID}) then {@Week List} And the list of missing weeks is: Week List local numbervar w; //Number of missing weeks local numbervar i; //Counter for loop local stringvar s:=""; //String to print out the result w:= (next({@Start of Week})- {@Start of Week})/7-1; //Calculate the number of missing weeks for i:= 1 to w do ( s:=s + totext({@Start of Week}+ (i*7), "dd-MMM-yyyy")+ chr(10) + chr(13)); s
This article is copyrighted by Crystalkeen, Mindconnection, and Chelsea Technologies Ltd. It may be freely copied and distributed as long as the original copyright is displayed and no modifications are made to this material. Extracts are permitted. The names Crystal Reports and Seagate Info are trademarks owned by Business Objects. |