Rollup fields are great for aggregating data from related records. Dynamics 365 has a nice extra option with rollup fields, where they allow you to easily rollup data from child fields by turning on ‘Use Hierarchy’, after selecting the Source. An example of this is shown below, this example counts the number of contacts related to an account and since it uses Hierarchy it will also include the number of contacts from child records.
As you can see setting Use Hierarchy yes allows you to also filter the child records. This allows you to add an extra filter to removed unwanted records such as inactive records. Below is the result of the rollup fields using the Hierarchy from the example above, with the ‘Top Level’ being the parent to both Parent Companies and the four ‘Child’ records being children to Parent Company A and B respectively.
As you can see in the table, the number of contacts the ‘Top Level’ account has is only 5 however, because the Rollup includes hierarchy it shows 201 contacts.
As you may have guessed this only works for self-referential relationship with the Hierarchy flag set to yes, for the Account entity this is the ‘Parent Account’ relationship. It is important to note that not all Self-Referential relationships are Hierarchical and you are only able to have one Hierarchical Relationship per entity. This means if you create a second self-referential relationship with the Hierarchical flag set to ‘Yes’ you will get this pop-up warning and the old Hierarchical relationship will be turned into a non-hierarchical relationship.