Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Crystal Reports

Charting on Print-Time Formulas


Overview
In Crystal Reports, you cannot create a chart off a print-time, or
WhilePrintingRecords formula. However, in Crystal Reports 9 and
above there is a workaround that allows you to pass the print-time
formulas from the main report to a subreport, and then create a chart in
the subreport.
Contents
INTRODUCTION ........................................................................................... 2
CREATE A CHART ON A PRINT-TIME FORMULA............................................. 2
Format the Report........................................................................................2
Create Running Total Formulas ..................................................................4
Insert and Link the Subreport ......................................................................5
Create the Chart ..........................................................................................6
FINDING MORE INFORMATION...................................................................... 7

4/14/2004 10:03 AM Copyright 2004 Business Objects. All rights reserved. Page 1


Introduction
In Crystal Reports (CR) 9 and above, a chart can be made off some, but
not all, formulas. Some formulas are evaluated while records are being
printed to the report. These formulas are called print-time or
WhilePrintingRecords formulas. You cannot create a chart directly off
print-time formulas but you can indirectly, using the technique
described in this document. This technique consists of four parts:
Formatting the report
Creating running total formulas for the 'On change of' and 'Show
value(s)' values.
Creating and linking a subreport
Inserting a chart in the subreport

NOTE All the formulas in this document can be written in either Crystal or Basic syntax. Each
example formula will be displayed in Crystal (black) and Basic (blue) syntaxes.

Create a Chart on a Print-Time Formula
The following example uses the Customer table from the Microsoft
Access database, Xtreme.mdb that is installed with Crystal Reports.
Format the Report
1. Insert the Customer Name and Last Year's Sales fields in the
Details section.
2. On the Insert menu click Summary. Click Customer.Last Year's
Sales from the Choose the field to summarize drop-down box.
Click Sum from the Calculate this summary drop-down box.
3. Create a formula named PerCent with the following syntax:

//This formula uses Crystal syntax.
WhilePrintingRecords;
Shared CurrencyVar curCounter;
Shared CurrencyVar curTotal;
curCounter := curCounter + {Customer.Last Year's
Sales};
curTotal := (curCounter/Sum ({Customer.Last Year's
Sales}))*100;
ToNumber(curTotal);
4/14/2004 10:03 AM Copyright 2004 Business Objects. All rights reserved. Page 2

cr9_charting_print_time.pdf



'This formula uses Crystal's Basic syntax.
Shared curCounter as Currency
Shared curTotal as Currency
curCounter = curCounter + {Customer.Last Year's
Sales}
curTotal = (curCounter/Sum ({Customer.Last Year's
Sales}))*100
formula = ToNumber(curTotal)

4. Insert this formula in the Details section.
5. On the Report menu, click Select Expert. In the Choose Field
dialog box, click Customer ID and then click OK. In the Select
Expert dialog box, click is less than from the drop-down box.
Choose 9 from the new drop-down box that appears.



Figure 1-1

When the report is previewed you will see eight customers with their
Last Year's Sales values. Under these values you will see a total for all
eight customers' Last Year's Sales. The PerCent formula shows a
running total of Last Year's Sales as a percentage of the sum of all
customers' Last Year's Sales. (See Figure 1-1)
Now that the report is formatted you want to create a chart that uses the
PerCent formula. On the Insert menu, click Chart. In the Available
Fields box; notice that the PerCent formula is not there. The PerCent
formula is a print-time formula and will not appear in the Chart
Expert.
4/14/2004 10:03 AM Copyright 2004 Business Objects. All rights reserved. Page 3

cr9_charting_print_time.pdf


Create Running Total Formulas
To be able to create a chart on the PerCent print-time formula, the first
step is to roll up the values that will be used as the On change of and
Show values values from the main report, into formulas that will be
used in a subreport.
1. Right-click the gray area to the left of the Details section and then
click Insert Section Below. There will now be both a Details a
and a Details b section.
2. Create a running total formula for the 'On Change Of' value for the
chart. In this case that will be the Customer Name field:

//This formula is written in Crystal syntax.
//Name this formula 'OnChangeOf'.
whileprintingrecords;
stringvar strOnChangeOf;
strOnChangeOf := strOnChangeOf + {Customer.Customer
Name} + "^";

' This formula is written in Crystal's Basic syntax.
' Name this formula 'OnChangeOf'.
global strOnChangeOf as string
strOnChangeOf = strOnChangeOf + {Customer.Customer
Name} + "^"
Formula = strOnChangeOf

3. Insert this formula in the Details b section.
4. Create a running total formula for the 'Show Value' value for the
chart. In this case that will be the Last Year's Sales field:

//This formula is written in Crystal syntax.
//Name this formula 'Show value'.
stringvar strShowValue;
strShowValue := strShowValue + totext({@PerCent}) +
"^";

' This formula is written in Crystal's Basic syntax.
' Name this formula 'Show Value'.
global strShowValue as string
strShowValue = strShowValue + totext({@PerCent}) +
"^"
Formula = strShowValue
4/14/2004 10:03 AM Copyright 2004 Business Objects. All rights reserved. Page 4

cr9_charting_print_time.pdf


5. Insert this formula in the Details b section.
6. Right-click the gray area to the left of the Details b section and then
click Suppress (No Drill-Down).


Figure 1-2

NOTE The Details b section is suppressed because the OnChangeOf and ShowValue formulas
do not need to be seen when the report is previewed. They do need to be evaluated,
though. When a section is suppressed, formulas in that section are evaluated without
being seen.

Insert and Link the Subreport
1. On the Insert menu, click Subreport. On the Insert Subreport
dialog box, enter "ChartSub" in the Report Name text box and
then click the Report Wizard button.
2. Move the Customer table into the Selected Tables box. Click the
Finish button and then click OK. Place the subreport in the
Report Footer section.
3. On the Edit menu, click Subreport Links. Move both the
OnChangeOf and ShowValue formulas to the Field(s) to link to
box.
4. In the Field(s) to link to box, click the OnChangeOf formula and
then clear the Select data in the subreport based on field check
box. Do the same thing for the ShowValue formula. Click OK.
5. Right-click the subreport and then click Edit Subreport. On the
Report menu, click Selection Formula >Record. Enter the
following selection formula:

{Customer.Customer Name} in split({?Pm-
@OnChangeOf},"^")

6. Click the Save button and then close the Record Selection
Formula Editor dialog box.
4/14/2004 10:03 AM Copyright 2004 Business Objects. All rights reserved. Page 5

cr9_charting_print_time.pdf


Create the Chart
1. In the subreport, create a formula with the following syntax:

// This formula is written in Crystal syntax.
// Name this formula 'SubShowValue'.
ToNumber(Split({?Pm-@ShowValue}, "^")[RecordNumber])

' This formula is written in Crystal's Basic syntax.
' Name this formula 'SubShowValue'.
formula = tonumber(split({?Pm-@ShowValue},
"^")(RecordNumber))

NOTE The @SubShowValue formula is based on recordnumber. If the records come into the
subreport in a different order from the order of the @OnChangeOf formula, then the
values will not match the groups.
To work around this, do a record sort in the subreport so that the subreport records are in
the same order as they are listed in the @OnChangeOf formula. Make sure that the
subreport only returns one record for each @OnChangeOf.

1. In the subreport, click the Insert menu, and then click Chart.
2. On the Type tab, click Bar.
3. On the Data tab, move the Customer.Customer Name field from
the Available fields box to the On change of box. Move the
SubShowValue formula from the Available Fields box to the
Show Value(s) box. Click OK.
4/14/2004 10:03 AM Copyright 2004 Business Objects. All rights reserved. Page 6

cr9_charting_print_time.pdf



Figure 1-3

When the report is previewed the bars in the chart show the value of the
PerCent print-time formula for each customer. (See Figure 1-3)
Finding More Information
For more information and resources, refer to the product documentation
and visit the support area of the web site at: www.businessobjects.com

www.businessobjects.com


The Business Objects product and technology are protected by US patent numbers 5,555,403;
6,247,008; 6,578,027; 6,490,593; and 6,289,352. The Business Objects logo, the Business Objects
tagline, BusinessObjects, BusinessObjects Broadcast Agent, BusinessQuery, Crystal Analysis, Crystal
Analysis Holos, Crystal Applications, Crystal Enterprise, Crystal Info, Crystal Reports, Rapid Mart, and
WebIntelligence are trademarks or registered trademarks of Business Objects SA in the United States
and/or other countries. Various product and service names referenced herein may be trademarks of
Business Objects SA. All other company, product, or brand names mentioned herein, may be the
trademarks of their respective owners. Specifications subject to change without notice. Not responsible
for errors or omissions. Copyright 2004 Business Objects SA. All rights reserved.
4/14/2004 10:03 AM Copyright 2004 Business Objects. All rights reserved. Page 7

cr9_charting_print_time.pdf

You might also like