Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

5.11 Creating Formulas, Calculations

Creating Formulas

The two most common reasons for using the Formula Workshop are for performing calculations and using conditional formatting. Both of these tasks involve different steps for creating the formula and working with it. The steps for doing each are described next.

Creating Calculations

A report gets the majority of its data from a data source. The data source could be a table in a database, an XML data feed or a proprietary data source. Since databases are designed to only store the necessary information, they don’t have extraneous information that can be derived by other means (e.g. calculations). It is more efficient to perform calculations on an as-needed basis than save the results within the database. It’s your job as the report designer to create the formulas that perform the calculations needed on a report.

To add a new formula in the Report Designer, go to the Field Explorer window and right-click on the Formula Fields node. Select New from the pop-up menu. This opens the Formula Workshop window where you type in the formula in the Definition area. When you are satisfied with the formula, click the Save and Close button. If there are no errors in the formula, the Formula Workshop closes and the Report Designer is shown again. The formula you just created is listed under the Formula Fields node.

Formulas are displayed on the report by dragging and dropping it from the Field Explorer window onto the report. When looking at a report, you can tell the difference between database fields and formulas because formula fields are prefixed with a @. To edit an existing formula field on the report, right click on it within the report designer and select Edit.