Skip to main content

Add a calculated field to a template

A calculated field is a new field that you add to the field list of a document. Its value comes from a formula on existing numeric fields, such as quantity times price. In this task you create a field that calculates the value of a bill line, and you insert it in the lines table. The dialogs are explained in Print designer dialogs. Calculated fields in reports have their own task: Add a calculated field.

Before you begin​

  • Open the print designer on a bill design, as in Design or change a print template.
  • A calculated field works on numeric fields: numbers, quantities, prices, percentages and other formulas. Text fields cannot go in it.
  • Calculated fields belong to the document type (the bill, for example) and are shared by all its designs and all users. To save the design where you insert them you need Print Templates - Modify or Print Templates - Add in the Users window.

Steps​

Create the field​

  1. Choose Insert > Fields > Calculated Field. The Calculated Field dialog opens.
  2. In Name type the field title: Line value. This is what shows in the field list and on the page.
  3. From Format choose Price. The format sets how the result is displayed. The default is Number.
  4. Click inside Expression. In Category choose the bill lines group, then double-click the quantity field in the Fields list. It goes into the formula at the cursor, shown with its title, and the program adds a space after it.
  5. Type *, then double-click the price field. The formula is now: quantity * price. The box accepts only digits, the operations +, -, * and /, and brackets.
  6. Check that the frame of the formula is not red. A red frame means the formula is invalid.
  7. Click Ok. The program saves the field and adds it to the field list under the group Calculated Fields.

Insert the field in the table​

  1. Put the cursor in a cell of the first row of the bill lines table. If the field list is not shown, choose View > Field List.
  2. Double-click Line value under Calculated Fields. The program writes the field title in the cell and puts the field in the cell below it.
  3. Click Preview and check that the value equals quantity times price in every line.
  4. Click Design, then Save.

Because the formula holds a field of the bill lines, the calculated field goes in tables only. If you try to insert it outside a table, the message "You can insert "…" field into table only." appears.

Aggregate in the totals​

To work out the total of a column in a place outside the table, such as the sum of the line values:

  1. Create a new field as in steps 1 to 7, named Values total.
  2. Put one field of the bill lines in Expression (such as Line value), then put the cursor inside it and choose Sum from Aggregate.
  3. Click Ok. A field that holds no table field that is not aggregated suits the page, so you can insert it anywhere in the page.

Edit or delete a calculated field​

  1. Choose Insert > Fields > Manage Calculated Fields. A list of the fields opens, with a preview of the formula.
  2. To edit a field, select it and click Edit, or double-click it. Change the name, the format or the formula and click Ok. Every design uses the new formula. The field title updates at once in the open design, and in other designs when you open them.
  3. To delete a field, select it, click Delete and confirm. If it is used in a design, the program does not delete it and lists the names of up to three of those designs. Delete it from those designs first and save them.
  4. Click Close.

Result​

The program saves the calculated field in the database on Ok, not when you save the design. It shows in the field list of all designs of this type and for all users. When printing, the program works out the formula for each document or line and prints the result in the format you chose. Nothing changes in the accounts or in the stock.

If something goes wrong​

MessageWhy it appearsWhat to do
Name is a required field.Name is empty on Ok.Type a title.
'…' name is already used.Another calculated field has the same title.Type another title.
Expression is a required field.You entered nothing in Expression.Enter a field or a number.
Invalid expression.The formula is incomplete, the brackets are unbalanced, or an operation has no second side.Fix it until the red frame goes.
All fields must belong to the same data set.You added a table field from a group other than the group of an earlier table field in the formula.Choose two fields of the same group.
Two or more calculated fields either directly or indirectly depend on each other.The formula depends on a calculated field that depends on it.Remove the circular dependency.
This formula can be inserted in table only. But it was inserted in the page in some documents.You edited the formula of a field placed in the page so that it became table-only.Use aggregated fields in the formula, or create a new field.
You can not delete this field because it is used in the following documents: …The field is placed in a design.Delete it from the listed designs and save them, then delete the field.

This page applies to alameen ERP 10, version 10.1.79.764.