Crystal Reports Tools: Improve Performance While Saving Time and Money

  Resources  
Best sellers:
cView
Report Analyzer
cViewSERVER
ReCrystallize

Crystal Reports: Free trial

Articles:
Administration
Advanced
Basic
Crystal eNL
Database

Financial
Problems Solved

Books:
CR Books

Database Books
Developer Books
Tools:
All CR Tools
CR Analyzers
CR Bestsellers
DataBase Tools
CR Graphics
International
CR Mail UFLs
ReCrystallizePro
CR Schedulers
CR UFLs
CR Viewers

Add'l:
About us

Contact Us
cViewSUITE Ppt
Support

Crystal Reports
on Steroids

Crystal Reports: Calendar, Traffic Light

Calendar Format Report to highlight performance thresholds

We want to share with you a calendar report that displays in a traffic light format, a monthly summary that highlights if a threshold has been met.

The report on the right uses some demonstration data and is grouped by a date field, by month.

he dates with a green background are where the value for that day exceeds the target, and the yellow values are where a lower threshold is met.

 

Click image to enlarge

If you are designing a report like this, make the threshold a parameter or even a constant formula. There are 35 fields with conditional formats for the traffic lighting, so by doing this, you don’t have to change all 35 formats each time the targets change. So the report has a Threshold parameter and other parameters for record selection.

The Calendar starts with seven text objects in the Group Footer. These display the days of the week. The convention seems to be to start the week on Sunday, but that is entirely up to you. A different start of the week doesn’t require major redesign of the report.

Critical to the entire process are a pair of formulas to calculate the start and end of the month for each month group. Start of Month is calculated as: Date(Year({Table.DateField}), Month({Table.DateField}),1)

The end of the month is calculated as:

Local numbervar m := month({Table.DateField}) + 1;

Local numbervar y := year({Table.DateField});

If m > 12 Then (m := m-12; y := y + 1);

Date(y,m,1) - 1

You then need seven formulas to calculate the date of the first row of the calendar. You could manage with one formula, but we believed that made the report more difficult to design and it could increase the risk of errors in writing the formulas. You do not need to put these on the page as they will be used elsewhere.

The formulas are called {@Sunday}, {@Monday} etc. One for each day of the week. The {@Sunday} Formula

looks like:

{@Start of Month} - DayofWeek({@Start of Month}) + 1

 

More....

 

The logic here has been used widely in our examples in the past. Subtracting the DayOfWeek from a date takes you back to the previous Saturday. Add one to get the Sunday for the start of the calendar.

The Monday formula looks like:

{@Sunday} + 1

The remaining days of the week are calculated by adding one to the previous day.

 

Now, there is a small omission on the calendar report just presented. Did you notice? The problem is the  December 2006 group in the report. That month is 31 days long and begins on a Friday. A month that starts on a Saturday has a similar problem.

You need to include two more running total fields. The {#Sun6} running total is similar to the other {#Sun..}

running totals. It has a conditional evaluate of

{GLTrans.TRDate}= {@Sunday} + 35

The conditional display string is

ToText({@Sunday}+35,"dd-MMM-yyyy")

The other conditional formatting you need is to suppress the field if the fifth row of dates isn’t needed. The

conditional format for the suppress of that field is

month({@Sunday}+35) <> month({Table.DateField})

Use a similar formula for the Monday column. Because no month is longer than 31 days, you only need a Sunday and a Monday formula.

 

Some reports can be designed with a footer section and all the values calculated using conditional Running Totals. This report uses that technique. You need 35 running totals to calculate the values for each day. Yes, we know there is a maximum of 31 days in a month, but there are five rows of seven days, so a running total is needed for each of these.

You might need expand this to 37 running total fields to solve one of the problems with the report above. It won’t happen until December 2007, but if a Month starts on a Saturday and is 31 days long, you need two more fields on the page to include the last few days of the month. An alternative is to wrap those final days back to the first line, like some calendars do.

 

The first row of Running Totals are called {#Sun 1}, {#Mon 1}, etc. The second row are called {#Sun 2}, {#Mon 2} , etc. Use an easy to remember naming system to identify these running totals.

The {#Sun 1} running total is displayed. Select a field you want to summarize or count. The conditional evaluation is

{Table.DateField}={@Sunday}

The reset is on change of group.

The {#Mon} running total looks almost the same but has a conditional evaluation of {Table.DateField}={@Monday}

Click image to enlarge

 

Similarly, use a specific day for the other running total fields for the first row.

The next row of running totals ( {#Sun 2}, {#Mon 2}, etc) continue the logic for the second week of the month.

The {#Sun 1} Conditional evaluation is

{Table.DateField}={@Sunday} + 7

All the other running totals for the second week add seven days to the day for that column. For the third week, add 14 days, and for the fourth and fifth weeks add 21 and 28 days respectively. Place these in five rows of seven columns each in the group footer. You have to use the footer as Running Total Fields only calculate for the first record when placed in a header section.

Very Important: Set the Report Option to “Convert All Other NULL Fields to default Values”. If the conditional evaluation fails to find any records, the total will be null rather than zero. We need a number rather than a NULL to process the remaining formulas.

 

So what you will have now is five rows of seven numbers in your group footer. You know that each represents the data for a different day, but that isn’t obvious yet.

Select the first Running Total ({#Sun 1} Right click to format field.

We can change the number to a display a date by setting the “Display String” property. This is on the common tab. The formula here is:

ToText({@Sunday},"dd-MMM-yyyy")

The display string for the other running totals uses the formula for the day relevant for that column. For the next row, add 7 to the day, add 14 for the next row, 21 and 28 for the next two.

It would be nice to also be able to see the value for that day. We can do this by using a ToolTip Text.

Click image to enlarge

 

So when you look at the report, hold your mouse over that date and the value for that day will appear. The ToolTip formula is the same for every running total and is:

totext(CurrentFieldValue,0)

The Traffic Lighting is also the same for every field on the report.. We used the background color for the field (on the Border tab) with a formula of:

if CurrentFieldValue > {?Threshold} then lime else

if CurrentFieldValue > 0 then yellow else nocolor

Apply shading to the days outside the current month in your Calendar

When we look at the calendar on the wall for January 2007, we also see days for December and February on the same page as a picture of a Tennessee waterfall. The days for these other months are often shaded differently. We can apply the same technique in this report. On the {#Sun 1} running total field, set the font conditionally with:

if {@Sunday} < {@Start of Month} then silver else black

Do a similar thing for the next five days in the top row. Make sure you use the formula for the day for that column. The {#Sat 1} field will not need this as it will always be a date in the current month.

Do a similar set of conditional fonts on the last row of the report. The font for {#Sat 5} is

if {@Saturday}+28 > {@End of Month} then silver else black

You need to do similar things back to the Monday on the final row. The Sunday will always be in the calendar, but the remainder of the bottom row might not be.

Now you have a presentable calendar with days color coded to show how the month has performed. By using running totals you can display values for every day in the month, regardless of whether there are data for that day or not.

 

Data for a range

But what if your data are for a range? This would be great for project and call center reports. To do this, you need only a small change to the evaluation condition. If your table has a start date and end date, use this

{Table.StartDate}<={@Tuesday} and {Table.EndDate}>={@Tuesday}

Use this with a conditional count or sum, and if the record starts on or before that date, and finishes on or after the same date, then it will accumulate for that day.

 
 

 

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.

 

These keywords may have brought you here: date differences, date problems, date inconsistencies, date differences, date schemes, date formats, crystal reports tutorials, crystal reports tips, crystal reports articles, crystal reports information, crystal reports tips, crystal reports help, crystal reports training