Using Formulas for Calculations
A report gets the majority of its data from a data source. This could be a table in a database, an XML data feed or a proprietary data source. Data usually consists of raw data that doesn’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 to save the results within the database. A formula can be calculated and displayed directly on the report or it can be used by other formulas.
Crystal Reports lets you add and edit formulas via the Field Explorer window in the report designer. Within the Field Explorer window, right click on any of the formula fields and select Edit or New to open the Formula Editor. You can also right click on the tree node Formula Fields. The Field Explorer window is shown in Figure 7-3.
Figure 7-3. The field explorer window.
Once you’ve added a formula to the Field Explorer, you can display it on a report by dragging and dropping it to the report. You can tell the difference between database fields versus formulas because the formula fields are prefixed with a @. If you want to edit a formula field on the report, right click on it within the report layout and select Edit.