- Another field type - the aggregated field - creates a calculated field using an aggregate function (Count, Sum, Average, Minimum and Maximum). First you must create a relation to the entity that contains the fields you want to summarize. Right-click on the entity that will contain the aggregated field and select New > Relationship.
- From the drop-down list select the RelatedEntity. The field Name will be automatically filled with the name of the related entity, but you can change it.
- After saving you have to add a Relationship Key. Right-click on the relationship and select New > Key.
- A new tab will open. The field Name will be automatically filled with the name of the related entity, but you can change it. As the BaseEntityField select
Idand as the RelatedEntityField select the corresponding field from the related entity, i.e. a foreign key in the related entity that is linked to the Id of the base entity (you can find a step by step tutorial for creating a foreign key here). Save.
- In case that you don't already have two entities (and database tables) but only one, you can also use the Create child entity wizard. Right-click on the name of the parent entity and select Actions > Create Child Entity.
- Fill in the Child Entity Name for the new child entity. The Master Entity is already filled. There is also an option to add another parent entity. Click on OK.
- The wizard will finish all steps for you - it will create a new entity with a foreign key, a relationship between the entities and also an index for the child entity.
- Now that you have two entities in a relationship, you can finally create the aggregated field. Right-click on your entity that will contain the aggregated field and select New > Aggregated Field.
- A new tab will open. From a drop-down list select the AggregationType. Then select the Relation from a drop-down list - this is the entity you have created the relationship to. Then from a drop-down list select the Field whose values will be aggregated. The Name will be filled automatically, but you can change it. The attributes Caption, DataLength and DataType will be inherited from the selected Field. Save.
- You have finished creating the aggregated field. One last task remains if you want the field to recalculate automatically with every change in the detail data. You have to add the related entity as a child entity to the master entity's data structure. If you don't have one yet, go to Entities and right-click on the entity's name and select Actions > Create Data Structure and it will be generated.
- Expand Data Structures in the Data Model in the Model Browser. Then expand the folder of your project and find the data structure of your master entity. Expand it and then again expand the subfolder Entities. Right-click on the entity and select New > Entity.
- In the new tab find the attribute Entity and from a drop-down list select your child entity. The Name will be filled automatically. Save and you have completed the process of creating an aggregated field.