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.
6 thoughts on “Dynamics CRM, Rolled up Fields and Hierarchical Relationships”
Nice explanation Neil. Graphical display of this subject is a winner.. Gold Medal !
LikeLiked by 1 person
Thanks Sofi, really glad you like it.
Very nice Neil. Do you know if it is somehow possible to calculate the total revenue only on Parent Acccount A (Top parent) and leave the total revenue of the child accounts empty?
Greets from Germany
When I have faced this issue I have taken a very low-tech approach. I have simply hidden the calulated total revenue when the parent account field is not blank. Using a simple business rule. (Meaning it only shows on the top level accounts.)
Granted the calculation logic is correct but presents a logic representation of the data for the end user.
Pingback: Links Úteis – I LOVE CRM
Pingback: MB2-716 (Microsoft Dynamics 365 Customization and Configuration) – Rollup Fields | Microsoft Dynamics 365 and Unified Service Desk