Skip to main content


         This documentation site is for previous versions. Visit our new documentation site for current releases.      
 

Creating a calculated field

Updated on April 6, 2022
Applicable to Theme Cosmos applications

Save time and improve the accuracy of the information in your case processing by creating a calculated field that automatically returns a value based on the input data. For example, you can create a field that calculates a length of stay at a hotel based on arrival and departure dates that a user provides.

Before you begin: If you want to calculate a value of a currency, decimal, integer, or percentage field by using a function, define an embedded data field in your data model. For more information, see Embedding data in a case.
  1. Navigate to a place where you want to add a calculated field:
    ChoicesActions
    Add a calculated field to a case type
    1. In the navigation pane of App Studio, click Case types, and then click the case type that you want to open.
    2. Click the Data model tab, and then click Add field.
    Add a calculated field to a data object
    1. In the navigation pane of App Studio, click Data.
    2. Click the data object that you want to open.
    3. Click the Data model tab, and then click Add field.
  2. In the Add field modal dialog box, in the Field name field, enter the name of the new field.
  3. In the Type field, select a field type that supports calculations, for example, Integer.
  4. Expand the Advanced section, and then select the This is a calculated field (read-only) checkbox.
    The checkbox is visible only for fields that support calculation.
  5. Define how an application calculates the field value:
    ChoicesActions
    Calculate a value by using an expression
    Note: All types of calculated fields support expressions.
    1. In the Calculation section, in the Function list, select Use expression.
    2. In the text field, enter an expression that you want to apply.
      For example: To calculate the length of stay at a hotel based on arrival and departure dates, enter .Departure - .Arrival.
    Calculate a value by using a custom decision table
    Note: All types of calculated fields support decision tables.
    1. In the Calculation section, in the Function list, select Use decision table.
    2. In the drop-down list, select Custom decision table, and then click the Gear icon.
    3. In a dialog box that opens, configure your decision table.
      For more information, see Calculating values with decision tables.
    4. Click Submit.
    Calculate a value by using an existing decision table
    Note: All types of calculated fields support decision tables.
    1. In the Calculation section, in the Function list, select Use decision table.
    2. In the drop-down list, select Existing decision table, and then select the decision table that you want to use.
    3. Click Submit.
    Calculate a value of a currency, decimal, integer, or percentage field by using a function
    1. In the Calculation section, in the Function list, select a type of a function that you want to apply.
      For example: To summarize values from multiple fields, select Sum of.
    2. In the Field list, select a single-value field from an embedded data field in your data model.
    3. Click Submit.
  6. Click Save.
For example: The following figure shows a design-time configuration and a run-time effect of a calculated field that automatically returns a number of nights during a hotel stay booking, based on arrival and departure dates that a user provides:
Calculated field
Design-time and run-time presentation of a calculated field.

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us