Skip to main content

Calculated fields

A calculated field is a new field that you add to the field list. Its value comes from an expression on the existing fields. The designer treats it like an ordinary field: you bind a control to it, group and sort by it, and use it in other expressions. This page is for implementers and support staff who build templates.

note

This calculated field belongs to the advanced report designer. The calculated field in the ordinary print designer has another page: Add a calculated field to a template.

Adding a calculated field​

You add the field in one of two ways:

  • Right-click a data source item in the Field List, and choose Add Calculated Field.
  • Or click Add Calculated Field on the ribbon. The ribbon describes it as creating a custom field whose value is calculated by an expression based on the available data fields.

The new field appears in the list, and you set the following for it:

SettingWhat you put in it
NameThe name of the field, which you see in the list and type in square brackets in expressions.
TypeThe type of the value the field calculates: a number, a text, a date or another type.
ExpressionThe formula that calculates the value.

You open the formula from the Expression property of the field in the Properties panel, and the Expression Editor appears. It is explained in The expression editor.

Editing and deleting calculated fields​

  • Right-click the field in the Field List, and choose Edit Calculated Fields... to open the Calculated Field Collection Editor, where you add, edit and delete fields.
  • To delete all the calculated fields at once, choose Remove All Calculated Fields.

Using the field​

You want toHow
Print itDrag it from the Field List to a band, like any field. See Field list and data binding.
Group or sort by itChoose it in the Group And Sort panel. See Group and sort.
Summarize itUse it in a summary function such as sumSum([LineValue]). See Summaries.
Use it in an expressionType it in square brackets like any field.

Example: the value of a line​

You want to print the value of each line of an invoice before discount, and their total at the end of the report.

  1. Right-click the group of invoice lines in the Field List, and choose Add Calculated Field.
  2. Name the field LineValue, and make its type a number.
  3. In Expression, type: [Price] * [Quantity].
  4. Drag LineValue to a cell in the line band, and wrap it in a function: ToPrice([LineValue]).
  5. In the Report Footer band, add a text with the expression ToPrice(sumSum([LineValue])).

Result: each line prints its value, and the invoice prints the total of the line values once at its end. Open the Preview tab and check the numbers with a calculator.

Where the field is saved​

The calculated field is saved in the template itself, not in the data source and not in the database. So it moves with the template when you export and import it, and it does not affect other templates. Its expressions depend on the names of the source fields, so if the procedure it reads from changes (see Create a custom data source), check the expressions.

This page applies to alameen ERP 10, version 10.1.79.764.