Rollup fields in Microsoft Dynamics CRM 2015 – What are they and how do they work?

Ahmed Anwar, 21 September 2014

Rollup fields are one of the new features introduced in Microsoft Dynamics CRM 2015 that saved extra effort on Developers to calculate aggregated data from a Children entity to a Parent entity. The creation and setup of a Rollup field is kind of similar to Calculated fields except for a few things.

Rollup fields in Dynamics CRM 2015

Let me give you an example to explain the Rollup fields. Let’s say a customer asked to create a new Entity called Class and Students and the relationship is 1:N. Each Student has a Name and a Score field. The customer asked you to create two fields on the Class entity to calculate the Highest Score and Low Score. The Highest value represents the highest score for all students associated to a particular class. The same thing applies to the lowest value as well but using the Lowest Score.

To keep it short, I’ll suppose that you already had created the entities.
Now to implement this requirement we need to create a Rollup field.

Go to an entity > Fields then click New.

 Rollup fields in Microsoft Dynamics CRM 2015

Rollup fields can only be used on Numerical Data Types:

• Whole Number
• Floating Point Number
• Decimal Number
• Currency
• Date and Time 
 

Click the Edit button to configure the field.

Select the Students entity (the Child entity). 

 Rollup fields in Microsoft Dynamics CRM 2015

For the Highest Score, we need to select the MAX function from the Aggregation Function list. 

 Rollup fields in Microsoft Dynamics CRM 2015

Also, you can add filtration options to filter you aggregation function based on a certain criteria.

The moment you click Save or Save And Close the logic is ready to be executed and there is no need to publish.

In the parent entity (Class) add the Rollup fields on your Form and add a Sub-Grid (Students).
After publishing, create a Class record with a few Students with random scores.

Important: You’ll notice that Rollup fields DO NOT automatically update/recalculate after creating/updating/deleting children records. You HAVE to click the Refresh button on the rollup field to get updated aggregated value.
So that means that rollup field does not update its value in the Database unless the user presses the refresh button. Therefore, Rollup fields are not effective when using:

• Process (Workflows\Dialogs)
• SDK
• Data Import

You have to be extremely cautious when working because current value does not mirror actual value.