Count the number of related child records using a Rollup field

Its going to be a very simple and basic blog where i will show you how you can count number of related records for e.g.

  1. number of cases related to account/contact
  2. number of opportunities related to account/contact
  3. number of active quotes for a contact

this list can go one. In short wherever you have 1:N relationship ; you should be able to perform this operation. it will show something like below :

1

 

  1. To do this create a field on parent record – select the name and select the data type as “whole number” and  field type as “RollUp”  :2
  2. after doing this as soon as you click on “edit” – it saves the field and give you an editor , just like a business rule select the cases(customer) as a related entity.
  3. you can define condition below that for e.g where status of the case  = active or where cases owner is a particular user.
  4. finally in the Aggregation select “COUNT” and in the next field it will show you just one option as case.
    3
  5. finally save the editor and put this field on the form. When you open the form after the publishing all customization , you might see this as 0 at first place its because rollup fields are nothing but system jobs in the background which runs at particular time ( 12 hours to be specific) but you can always force it by clicking to that refresh button in the field :
    5

once all done you will have this field showing you the related records count.

 

i hope this helps!

Advertisement

Calculated Vs Roll Up Field

Hi folks , i have gathered a quick summary of important differences between a calculate field and a roll up field:

Calculated Field Roll Up Field
Data is calculated as soon as form is loaded The rollups are calculated by scheduled system jobs that run asynchronously in the background.
calculated fields let you automate manual calculations used in your business processes. . A rollup field contains an aggregate value computed over the records related to a specified record
The calculated fields comprise of calculations that use the fields from the current entity or related parent entities. The roll up fields comprise of Aggregation that use the fields from the current entity or related child entities.
The expression support is available on the current entity and the related parent entity fields in the Condition sections and the Action sections. The built-in functions include:

ADDHOURS, ADDDAYS, ADDWEEKS, ADDMONTHS, ADDYEARS, SUBTRACTHOURS, SUBTRACTDAYS, SUBTRACTWEEKS, SUBTRACTMONTHS, SUBTRACTYEARS, DIFFINDAYS, DIFFINHOURS, DIFFINMINUTES, DIFFINMONTHS, DIFFINWEEKS, DIFFINYEARS, CONCAT, TRIMLEFT, and TRIMRIGHT.

Wide selection of aggregate functions. You can aggregate data by using the following functions: SUM, COUNT, MIN, MAXand AVG.
A seamless integration of the calculated fields with the forms, views, charts, and reports is available in real time. eamless integration with the user interface. You can include the rollup fields in forms, views, charts and reports.
The available data types for the calculated field:
Single line of text,Option Set,Two Options,Whole Number,Decimal Number,Currency,Date and Time
The data types include decimal or whole numbers, currency, and date/time.

Above data has been collected from Microsoft technet.

if you wish to know more about these fields in-depth, please follow below:

Calculated Field :  https://technet.microsoft.com/en-us/library/dn832103.aspx

Rollup Field :  https://technet.microsoft.com/en-us/library/dn832162.aspx

 

Hope this helps!

Cheers!