You can use ->average in OCL to calculate the mean of a collection of numeric values, such as order totals, when defining expressions in MDriven Designer.
Purpose
The average operator iterates over a collection of numeric values and returns their arithmetic mean.
The collection must contain values of type Integer, Decimal, or Real. For example, an order collection can provide its Total values as the input collection.
Syntax
collection->average| Part | Meaning |
|---|---|
collection
|
A collection of numeric values. |
->average
|
Calculates the mean value of the values in that collection. |
Calculate an average from an attribute
To calculate the average value of an attribute across objects, first navigate from the object collection to the attribute values, then apply ->average.
- Identify the objects to include. In this example, use all
Orderobjects. - Select the numeric attribute to average,
Total. - Apply
->averageto the resulting collection of totals.
Order.allInstances.Total->averageThis expression returns the mean value of the Total attribute across all Order objects.
For example, if the selected order totals are 100, 150, and 200, the expression returns 150.
Use the operator with the correct value collection
Apply ->average after an expression that produces numeric values. Do not apply it directly to a collection of objects unless the preceding navigation selects a numeric attribute.
| Expression | Result |
|---|---|
Order.allInstances.Total->average
|
Averages the numeric Total values for all orders.
|
Order.allInstances->average
|
Does not provide a collection of numeric values; select a numeric attribute first. |
Related operators
Use ->average when you need the mean. Use ->minValue or ->maxValue when you need the lowest or highest value instead. Use the divide operator (/) for arithmetic division in an expression.
Find operators in the OCL editor
To browse available OCL operators, open the OCL Editor and type a class name, as described in Documentation:OCL General Operators.
