Examples
Example1
For each case (instance), calculate the average value of the activity field "value" for all activities assigned to the case instance.
Query
New "Case" field:
PU_AVG("Case", "Activity", "Activity"."aValue")
Target: "Case" object
Scope: "Case" object
Source: "Activity" object
Value: "Activity"."aValue"
Processing

For each case iterate over all assigned activities of the case and calculate the average of the activity field "aValue". Since the target and scope are the same object (case), we simply iterate over the target object.
Explanation
In this simple example, the definition of the scope does not matter. Whenever the target object is the case (the root), the scope must also be the root object (the case).
Input/Output
Case
caseId:text | cValue:number |
c1 | 100 |
c2 | 200 |
Activity
parentCaseId | activityId:string | activityName:string | aValue:number |
c1 | a1 | A | 100 |
c1 | a2 | B | 200 |
c2 | a3 | A | 400 |
c2 | a4 | B | 600 |
New case field
caseId:text | cValue:number | newField:number |
1 | 100 | 300 |
2 | 200 | 500 |
Example 2
For each case (instance) calculate the average of the sum of the role field "rValue" and the activity field "aValue" (to which the role is assigned to) for all roles assigned to the case instance over the activity instance.
Query
New "Case" field:
PU_AVG("Case", "Role", "Role"."rValue" + "Activity"."aValue")
Target: "Case" object
Scope: "Case" object
Source: "Role" object
Value: "Role"."rValue" + "Activity"."aValue"
Processing

For each case iterate over all assigned activities and for each activity iterate over all assigned roles and calculate the average of the sum of the role field "rValue" and the activity field "aValue" (of the activity the role is assigned to).
Since the target and scope are the same object (case), we just iterate over the target object instances.
Explanation
In this example, when aggregating the values for the source object (the role), you can access not only fields of the source object but also fields of the activity to which the role is assigned.
Since the parent activity (but also the parent case) is uniquely determined when traversing the hierarchy (1-N relationship), all values of parent instances can be accessed when aggregating the values for the source object.
Input/Output
Case
caseId:text | cValue:number |
c1 | 100 |
c2 | 200 |
Activity
parentCaseId | activityId:string | activityName:string | aValue:number |
c1 | a1 | A | 100 |
c1 | a2 | B | 200 |
c2 | a1 | A | 400 |
c2 | a2 | B | 600 |
Role
parentCaseId | activityId:string | roleId:string | roleName:string | rValue:number |
c1 | a1 | r1 | Vendor | 100 |
c1 | a1 | r2 | Supplier | 200 |
c1 | a2 | r2 | Supplier | 200 |
c1 | a2 | r3 | Inspector | 300 |
c2 | a1 | r1 | Vendor | 100 |
c2 | a1 | r3 | Inspector | 300 |
c2 | a2 | r1 | Vendor | 100 |
c2 | a2 | r2 | Supplier | 200 |
New case field
caseId:text | cValue:number | newField:number | |
1 | 100 | 350 | ((100 + 100) + (200 + 100) + (200 + 200) + (300 + 200)) / 4 |
2 | 200 | 675 | ((100 + 400) + (300 + 400) + (100 + 600) + (200 + 600)) / 4 |
Example 3
For each role (instance) calculate the average of the location field "lValue" for the locations assigned to the activity, to which the role is assigned to.
Query
New "Role" field:
PU_AVG("Activity", "Location", "Location"."lValue")
Target: "Role" object
Scope: "Activity" object
Source: "Location" object
Value: "Location"."lValue"
Processing

For each role pick the activity instance the role is assigned to. Starting from this activity iterate over all assigned locations and calculate the average of location field "lValue".
Explanation
In this example, the target object is not the root. Therefore, when iterating, the hierarchy is traversed to the role instances. In this case, the source object can also be a subordinated object of an object that was passed along the way. In the example, the source object is the location, which is a subordinated object of the activity. Since for each role instance the activity instance to which it is assigned is unique (N-1 relationship), the set of locations (source object) used for aggregation is also definite.
This is also where the scope comes into play. Since the case to which the role belongs is also unique, all locations that are under the concrete case (via the assigned activities) could be aggregated or only those that are under the concrete activity. If the case object is selected as the scope, all locations below the concrete case (and the corresponding activities) are used for the aggregation. If the activity is selected as the scope, only those that are below the concrete activity will be taken into account.
Input/Output
Case
caseId:text | cValue:number |
c1 | 100 |
c2 | 200 |
Activity
parentCaseId | activityId:string | activityName:string | aValue:number |
c1 | a1 | A | 100 |
c1 | a2 | B | 200 |
c2 | a1 | A | 400 |
c2 | a2 | B | 600 |
Role
parentCaseId | activityId:string | roleId:string | roleName:string | rValue:number |
c1 | a1 | r1 | Vendor | 100 |
c1 | a1 | r2 | Supplier | 200 |
c1 | a2 | r2 | Supplier | 200 |
c1 | a2 | r3 | Inspector | 300 |
c2 | a1 | r1 | Vendor | 100 |
c2 | a1 | r3 | Inspector | 300 |
c2 | a2 | r1 | Vendor | 100 |
c2 | a2 | r2 | Supplier | 200 |
Location
parentCaseId | activityId:string | locationId:string | locationName:string | lValue:number |
c1 | a1 | l1 | Rome | 100 |
c1 | a1 | l1 | Rome | 100 |
c1 | a2 | l2 | London | 200 |
c1 | a2 | l1 | Rome | 100 |
c2 | a1 | l2 | London | 200 |
c2 | a1 | l2 | London | 200 |
c2 | a2 | l2 | London | 200 |
c2 | a2 | l1 | Rome | 100 |
New role field
parentCaseId | activityId:string | roleId:string | roleName:string | newFild:number | |
c1 | a1 | r1 | Vendor | 100 | (100+100) / 2 |
c1 | a1 | r2 | Supplier | 100 | (100+100) / 2 |
c1 | a2 | r2 | Supplier | 150 | (200+100) / 2 |
c1 | a2 | r3 | Inspector | 150 | (200+100) / 2 |
c2 | a1 | r1 | Vendor | 100 | (100+100) / 2 |
c2 | a1 | r3 | Inspector | 100 | (100+100) / 2 |
c2 | a2 | r1 | Vendor | 150 | (200+100) / 2 |
c2 | a2 | r2 | Supplier | 150 | (200+100) / 2 |
Example 4
For each role (instance) calculate the average of the location field "lValue" for the locations assigned to the case, to which the role is assigned to.
Query
New "Role" field:
PU_AVG("Case", "Location", "Location"."lValue")
Target: "Role" object
Scope: "Case" object
Source: "Location" object
Value: "Location"."lValue"
Processing

For each role pick the case instance to which the role is assigned to (via the unique activity instance). Starting from this case iterate over all activities which are assigned to the case and
for each activity iterate over all locations which are assigned to the activity and calculate the average of location field "lValue".
Explanation
In this example, the target object is not the root. Therefore, when iterating, the hierarchy is traversed to the role instances. In this case, the source object can also be a subordinated object of an object that was passed along the way. In the example, the source object is the location, which is a subordinated object of the activity. Since for each role instance the activity instance to which it is assigned is unique (N-1 relationship), the set of locations (source object) used for aggregation is also definite.
This is also where the scope comes into play. Since the case to which the role belongs is also unique, all locations that are under the concrete case (via the assigned activities) could be aggregated or only those that are under the concrete activity. If the case object is selected as the scope, all locations below the concrete case (and the corresponding activities) are used for the aggregation. If the activity is selected as the scope, only those that are below the concrete activity will be taken into account.
Input/Output
Case
caseId:text | cValue:number |
c1 | 100 |
c2 | 200 |
Activity
parentCaseId | activityId:string | activityName:string | aValue:number |
c1 | a1 | A | 100 |
c1 | a2 | B | 200 |
c2 | a1 | A | 400 |
c2 | a2 | B | 600 |
Role
parentCaseId | activityId:string | roleId:string | roleName:string | rValue:number |
c1 | a1 | r1 | Vendor | 100 |
c1 | a1 | r2 | Supplier | 200 |
c1 | a2 | r2 | Supplier | 200 |
c1 | a2 | r3 | Inspector | 300 |
c2 | a1 | r1 | Vendor | 100 |
c2 | a1 | r3 | Inspector | 300 |
c2 | a2 | r1 | Vendor | 100 |
c2 | a2 | r2 | Supplier | 200 |
Location
parentCaseId | activityId:string | locationId:string | locationName:string | lValue:number |
c1 | a1 | l1 | Rome | 100 |
c1 | a1 | l1 | Rome | 100 |
c1 | a2 | l2 | London | 200 |
c1 | a2 | l1 | Rome | 100 |
c2 | a1 | l2 | London | 200 |
c2 | a1 | l2 | London | 200 |
c2 | a2 | l2 | London | 200 |
c2 | a2 | l1 | Rome | 100 |
New role field
parentCaseId | activityId:string | roleId:string | roleName:string | newFild:number | |
c1 | a1 | r1 | Vendor | 125 | (100+100+200+100) / 4 |
c1 | a1 | r2 | Supplier | 125 | (100+100+200+100) / 4 |
c1 | a2 | r2 | Supplier | 125 | (100+100+200+100) / 4 |
c1 | a2 | r3 | Inspector | 125 | (100+100+200+100) / 4 |
c2 | a1 | r1 | Vendor | 175 | (200+200+200+100) / 4 |
c2 | a1 | r3 | Inspector | 175 | (200+200+200+100) / 4 |
c2 | a2 | r1 | Vendor | 175 | (200+200+200+100) / 4 |
c2 | a2 | r2 | Supplier | 175 | (200+200+200+100) / 4 |
Example 5
For each case (instance) calculate the sum of the aggregated role value, aggregating the maximum of the field value "iValue" for the items assigned to each order, which is assigned to the same case the role is assigned, to.
Query
New "Case" field:
PU_SUM("Case", "Role", PU_MAX("Case", "Item", "Item"."iValue"))
Target: "Role" object
Scope: "Case" object
Source: "Role" object
Value: PU_MAX("Case", "Order", "Item"."iValue")
Nested Aggregation
Target: "Role" object
Scope: "Case" object
Source: "Item" object
Value: "Item"."iValue"
Processing

For each case calculate the sum of the aggregated role value which is calculated by picking the case instance to which the role is assigned to (via the unique activity instance). Starting from this case iterate over all orders which are assigned to the case and for each order iterate over all items which are assigned to the order and calculate the maximum of item field "iValue".
Explanation
In this example, the aggregated value for each role is a further aggregation. In this case, the aggregation starts on each role which is the source for the outer aggregation.
For the embedded aggregation, the target is the role. Within the embedded aggregation, the source object can be any object that is subordinate to the target object or that is subordinate to an object that has been traversed (for the outer aggregation).
Input/Output
Case
caseId:text | cValue:number |
c1 | 100 |
c2 | 200 |
Activity
parentCaseId | activityId:string | activityName:string | aValue:number |
c1 | a1 | A | 100 |
c1 | a2 | B | 200 |
c2 | a1 | A | 400 |
c2 | a2 | B | 600 |
Role
parentCaseId | activityId:string | roleId:string | roleName:string | rValue:number |
c1 | a1 | r1 | Vendor | 100 |
c1 | a1 | r2 | Supplier | 200 |
c1 | a2 | r2 | Supplier | 200 |
c1 | a2 | r3 | Inspector | 300 |
c2 | a1 | r1 | Vendor | 100 |
c2 | a1 | r3 | Inspector | 300 |
c2 | a2 | r1 | Vendor | 100 |
c2 | a2 | r2 | Supplier | 200 |
Order
parentCaseId | orderId:string | oValue:number |
c1 | o1 | 100 |
c1 | o2 | 200 |
c2 | o3 | 400 |
c2 | o4 | 800 |
Item
parentCaseId | orderId:string | itemId:string | iValue:number |
c1 | o1 | i1 | 200 |
c1 | o1 | i2 | 400 |
c1 | o2 | i3 | 800 |
c1 | o2 | i4 | 1600 |
c2 | o3 | i5 | 500 |
c2 | o3 | i6 | 700 |
c2 | o4 | i7 | 900 |
c2 | o4 | i8 | 1800 |
New case field
caseId:text | cValue:number | newField:number | |
1 | 100 | 6400 | (1600 + 1600 + 1600 + 1600) |
2 | 200 | 7200 | (1800 + 1800 + 1800 + 1800) |