Sub topic 6
Summarizing fields within groups
This chapter covers how Salesforce calculates totals, averages, minimums, maximums, and record counts for each group in a report. It assumes you can open the report builder in Lightning Experience, know what a report type is, and have already grouped rows by a field such as Stage or Owner. If grouping is new to you, read the previous chapter first.
What a summary does
A grouping splits report rows into sets. A summary then reduces each set to one number. In a report grouped by Stage, the summary of Amount for the Prospecting group is a single value computed from all Prospecting rows.
Salesforce calculates a summary at every level of the report:
- Each group gets its own subtotal.
- Each nested subgroup gets its own subtotal.
- The whole report gets a grand total.
Summaries are available only when the report has at least one grouping, or in a matrix. A tabular report has no groups, so it can show only a grand total.
The five summary functions
For a numeric, currency, or percent field, you can choose any of these functions:
| Function | What it returns | Typical use |
|---|---|---|
| Sum | Adds the values in the group | Total pipeline by stage |
| Average | Sum divided by the number of rows that have a value | Average deal size by owner |
| Max | Largest value in the group | Biggest deal per region |
| Min | Smallest value in the group | Earliest or smallest item |
| Record Count | Number of rows in the group | Number of opportunities per stage |
Record Count is different from the others because it does not belong to a field. It counts rows, and it is available in any report that has groupings.
Date fields can also be summarized with Min and Max. For example, Max of Last Activity gives the most recent activity in the group. Text fields cannot be summed or averaged.
How to add a summary
In the report builder:
- Open the report and make sure at least one grouping exists.
- In the Outline panel, find the field you want to summarize.
- Open the field's menu and choose Summarize this Field.
- Select the functions you want, such as Sum and Average.
- Select Apply.
You can select several functions for one field. Each one appears as its own column in the group subtotal rows.
Worked example: Opportunities by Stage
Suppose an Opportunity report has Stage as its row grouping. You summarize Amount with Sum and Average, and you show Record Count.
| Stage | Record Count | Sum of Amount | Average of Amount |
|---|---|---|---|
| Prospecting | 4 | 40,000 | 10,000 |
| Negotiation | 3 | 90,000 | 30,000 |
| Closed Won | 5 | 150,000 | 30,000 |
| Grand total | 12 | 280,000 | 23,333 |
The Average on the grand total row is 23,333, not the average of 10,000, 30,000, and 30,000. Salesforce computes each total from the underlying rows: 280,000 divided by 12 rows. This is the correct way to average, and it is a common source of confusion when someone checks the numbers by hand.
Filters run before summaries
Filters remove rows before any summary is calculated. If you filter to Close Date in the current fiscal year, every subtotal and the grand total include only those rows. The summary never sees the excluded rows.
This order explains a frequent mistake. A user adds a filter, then wonders why a group's count dropped. The group did not change. Its input rows did.
There is one exception worth knowing. In a summary report you can show only the top groups, or limit rows with a chart. These options affect what is displayed, not what the grand total contains. Check whether a number on screen comes from a filter or from a display setting.
How blanks and nulls are handled
Summaries ignore empty values in numeric fields:
- Sum treats an empty field as contributing nothing.
- Average divides by the number of rows that have a value, not by every row.
- Min and Max skip empty values.
- Record Count counts every row, whether or not the field is filled in.
Suppose a group has three opportunities with Amounts of 10,000, 20,000, and blank. The Sum is 30,000. The Average is 15,000, because only two rows have a value. Record Count is 3.
If you want blanks to count as zero, you cannot do it with the standard Average. You would need a custom summary formula, covered in a later chapter. A formula such as the following divides the sum by the full row count:
AMOUNT:SUM / RowCountThis returns the sum of Amount divided by every row in the group, so a blank Amount lowers the result as if it were zero.
Summaries across multiple groupings
When a report has nested groupings, such as Stage and then Owner, each level has its own subtotal. The inner level summarizes rows for one owner within one stage. The outer level summarizes all rows in the stage.
The outer subtotal is calculated from the underlying rows, not from the inner subtotals. For Sum and Record Count the result is the same either way. For Average, Min, and Max it can differ, so do not average the averages.
You can control how much detail you see in the report builder:
- Show Details displays the individual rows under each group.
- Hide Details shows only the group headings and subtotals.
- Subtotals can be turned on or off to hide or show the summary rows.
Hiding details makes large reports faster to read and is the usual setup before adding a chart.
Summaries in matrix reports
In a matrix report, a summary is computed for every cell where a row grouping meets a column grouping. A matrix of Stage by Close Year shows the Sum of Amount for each stage and year, plus totals at the end of each row and column.
If you choose more than one summary, such as Sum and Record Count, each cell shows both. Wide matrices with several summaries become hard to read, so choose the smallest set that answers the question.
The same idea in SOQL
Summaries in a report correspond to aggregate functions in SOQL, the Salesforce query language. The grouping becomes GROUP BY, and each summary becomes a function in the select list. This query returns what the Opportunities-by-Stage report above shows:
SELECT StageName, SUM(Amount) total, COUNT(Id) cnt
FROM Opportunity
GROUP BY StageNameSUM(Amount) matches the Sum summary and COUNT(Id) matches Record Count. SOQL also has AVG, MIN, and MAX, which match the other three functions.
One difference matters. The SOQL AVG(Amount) also skips null values, which matches the report behavior described above. Reports add grand totals and subtotal rows for you, while SOQL returns only the groups unless you use GROUP BY ROLLUP.
Common errors
- Summarizing the wrong field. Sum of a percent field or a rate gives a meaningless number. Use Average, or a formula that divides two sums.
- Reading Average without Record Count. One large deal in a group of one produces an impressive average.
- Mixing currencies. In orgs with multiple currencies, report amounts are converted to a single currency for summaries. Check the report's currency setting before comparing numbers with another system.
- Expecting totals to match the chart. If the chart limits the number of groups shown, the chart can show less than the grand total.
- Forgetting that filters come first. A changed count usually means a changed filter, not changed data.
Exercises
Exercise
A group of four opportunities has Amounts of 8,000, 12,000, 20,000, and a blank. What are the Sum, Average, and Record Count that Salesforce shows for the group?
Show answer
Sum is 40,000. Average is 13,333 (40,000 divided by the three rows that have a value). Record Count is 4, because it counts every row regardless of blank fields.
Exercise
A summary report grouped by Owner shows an Average Amount of 90,000 for one owner. You suspect this is misleading. Which additional summary should you add, and why?
Show answer
Add Record Count. If the owner has only one or two opportunities with values, the average rests on very little data. Record Count shows how many rows the average is based on.
Exercise
You need the average Amount per opportunity in each stage, counting blank Amounts as zero. Which approach produces it?
Show answer
Create a custom summary formula that divides the group's sum by its row count: AMOUNT:SUM / RowCount. The standard Average skips blanks, but RowCount includes every row.