Server Administration > Calculations in Fields, Charts, and Reports > Creating a Computed Field
  
Creating a Computed Field
Computed fields allow you to perform intra-item or inter-item calculations, storing the result as a value in a read-only field (the computed field). Intra-item calculations are performed on one or more fields within the same item that contains the computed field, while inter-item calculations are performed on fields from other items referenced through an aggregation function on a relationship or on a query.
Primarily, there are three parameters that define a computed expression field:
Computation Definition
Store to History Frequency
How to Run Computations
Computation Definition
This is the actual computation expression. For more information, see Computed Expression Rules.
Store to History Frequency
This is where you specify how frequently you want Windchill RV&S to store the result of the expression to the database. The available options are:
never: Never store the result to the database.
daily: Store the result of the computation to the database every day.
weekly: Store the result of the computation to the database every week.
monthly: Store the result of the computation to the database every month.
delta: Store the result of the computation to the database for every delta.
* 
These computations depend on the execution of respective triggers and are valid only when the value of How to Run Computations is static.
How to Run Computations
This parameter determines how do you want to run the computations. The available options are:
static calculates the field based on a schedule and stores it in the item’s history based on the value selected in the Store to History Frequency list. Columns for static fields are stored in the item’s row of the database. You should select static if your expression involves intensive external functions, such as query or aggregate functions. For more information on calculating a static computed field, see Calculating Static Computed Fields.
dynamic calculates the field every time field values are retrieved. By default, columns for dynamic fields are not stored in the item’s row of the database; however, you can select dynamic and the frequency from the Store to History Frequency list for which never is an appropriate option. dynamic is the default option.
Key Considerations
If you create an expression using one or more fields that a user does not have permission to view, the user sees only the fields they have permission to view.
Computed fields are calculated in the order that they appear in the item; however, if a computed field depends on the value of another computed field, it is calculated after the computed field containing the dependent value. Depending on the number of items in your database and the number of items containing computed fields that contain dependencies, it may take a long time to calculate the value of the computed fields.
Using the im analytics --recomputehistory -g command, you can calculate a computed field within a specific time frame, storing the value in the item history. This command is useful for historical trend charting; however, it does not allow you to “correct” the history of current item data. For more information, see Using Computed Fields to Calculate State Metrics.
Computed text fields only accept numeric, short text, and long text fields.
You cannot create editability rules for field value attributes backed by any computed field.
If you create a dynamic computed field, but choose to later convert it to a static computed field to improve performance, see Calculating Static Computed Fields.
Example: Open Task Count
Open Task Count is an integer field that displays the number of open tasks (Change Orders, Defects and Test Objectives) belonging to an item and all sub-items. For products and product portfolios, only active projects are included. For project portfolios, all projects are included. The calculation assumes that only task-like objects such as Change Order and Defect expose the Task Phase field.
Computation Definition:
IsEmpty("Open Change Order Count for Project",0) +
IsEmpty("Open Defect Count",0) +
IsEmpty("Open Test Session Count",0)
Store To History Frequency: daily
How To Run Computations: static
Example: New Defect Count - Priority Critical
New Defect Count - Priority Critical is an integer field that identifies critical priority defects.
Computation Definition:
IsEmpty(Query("administrator:New Defects - Priority Critical",Project,count()), 0)
Store To History Frequency: weekly
How To Run Computations: static
Example: Test Session Tests Count
Test Session Tests Count is an integer field that displays Test cases currently defined by the Tests field on a Test Session. This is an interim field used by the Freeze Date Tests Count field.
Computation Definition:
aggregate(Tests, byDocument(true,true),sum(isTestcase() and isMeaningful() ? 1 : 0))
Store To History Frequency: never
How To Run Computations: dynamic
Example: Validated By Pass Percentage
Validated By Pass Percentage is an integer field that determines the percentage of Validated By Trace Count which have a last results of Passed. This is used by Requirements Test Coverage and Specification Test Coverage reports to display test status per requirement and per specification.
Computation Definition:
"Validated By Trace Count" > 0 ? ( (isEmpty("Validated By Pass Count",0) + 0.001)
/ "Validated By Trace Count") : 0
Store To History Frequency: daily
How To Run Computations: static
Example: Count of Related Items Based on a Specific Type
Total Related Test Types is an integer field that counts the number of Test Type items in an item’s Forward Relationships field, ignoring all other item types. This is useful for reporting on a specific item type in a relationship field (the default report recipes included in Windchill RV&S report on all item types in the Forward Relationships field).
Computation Definition:
IsEmpty(aggregate("Forward Relationships", sum((Type = "Test_Type") ? 1: 0)), 0)
Store To History Frequency: daily
How To Run Computations: static
To create a computed field