In previous posts about Microsoft Dynamics CRM I have explained how hierarchical relationships operate and how rolled up fields are created. It is possible to combine both of these concepts, something I didn’t explain!
This post will explain how to roll up fields within a hierarchy.
Say each account has a revenue field. And you have a hierarchy of parent and child accounts. In this scenario it might be useful to see a rolled up value of total revenue for the group of accounts. It could also be helpful to see a count of how many children each parent has.
Here I will explain how to create these rolled fields and also comment on what values they would then hold for the parent and child accounts.
Out of the box a hierarchical relationship exists between parent and child accounts. So I will use that for this example. But this logic will also work on custom entities / relationships.
I created two fields. One called “Total Revenue” that would sum the Revenue field. And another call “Count of Branches”. This would could the number of children each account record has. You can see below my total revenue field. This is a currency field that in the field type I have changed the type from Simple to Rollup. Next I clicked edit to set the roll up details.
Having selected edit I created the roll up logic for my new total revenue field. (Shown below.) Notice that I have changed the “Use Hierarchy” setting to Yes and selected a relationship. (Actually only one hierarchical relationship was present was it was defaulted in!) Also notice that I select “Sum of Annual Revenue” as my aggregation. Annual Revenue is an out of the box field on the Account entity but you could obviously also use custom fields if required.
Having created the total revenue field, I created my count of branches. The field was pretty similar to total revenue, except the data type for my count was whole number. I still said it was a Rollup field and continued to click edit to define the detail.
My roll up field details were pretty similar. I selected yes to the hierarchy option and selected the same relationship as before. But this time my aggregation was “Count of Account”.
I then added this fields, with the additional fields created for rollup fields to my form.
Note: The additional fields are when the value was last rolled up and its state. If you don’t understand how these fields operate or would like to know more about when the roll up happens, I suggest you refer to my earlier post on rolling up fields.
All is good. J
But the reason I did this test was to understand what values will be in my total revenue and count of branch fields for the parent and child accounts. Especially when the hierarchy has multiple levels. I had some questions!
- If the parent account has revenue will it be included in the total revenue field? (The answer is yes!)
- For the count will just the children be counted? (The answer is yes!)
- Will the values show correctly in a multi-level hierarchy? (The answer is yes!)
The graphic below shows the results I obtained in a multi-level hierarchy.
Hopefully this post has given you an insight into how hierarchical roll up fields operate.