Sub topic 5
Grouping rows
This chapter assumes you can build and run a tabular report in Lightning Experience. You should know what a report type is and how filters narrow records. Grouping is the step that turns a flat list of records into a summary report. It is also the basis for the row and column axes of a matrix report.
What a grouping does
A row grouping sorts report records into buckets that share a value in one field. In a tabular report, every record is a row. Once you group by a field, Salesforce collects records with the same value under one heading. Records that were rows in a flat list now sit beneath a group header.
For example, a tabular report of opportunities lists one line per opportunity. If you group by Stage, you get one section for Prospecting, one for Negotiation, one for Closed Won, and so on. Each section holds the matching opportunities.
A grouping does not change which records are in the report. Filters and scope decide that. A grouping only changes how the records are arranged and what you can total.
Adding a grouping in the report builder
In Lightning report builder, you can add a grouping in several ways:
- Open the report and find the Group Rows box in the Outline panel.
- Type or pick a field. You can also drag a column header into the box.
- Add a second field to the same box to create a subgroup.
The report format changes to summary as soon as the first row grouping exists. You do not choose "summary" separately.
Which fields can you group by? Most text, picklist, date, lookup, and checkbox fields work. Long text areas and some other field types cannot be grouped. Bucket fields and row-level formulas can be grouped, which is useful when no existing field has the categories you need.
Group levels and limits
The number of groupings depends on the format.
| Format | Row groupings | Column groupings |
|---|---|---|
| Tabular | 0 | 0 |
| Summary | Up to 3 | 0 |
| Matrix | Up to 2 | Up to 2 |
| Joined | Set per block, with common groupings shared across blocks | Not applicable |
The order of groupings matters. If you group opportunities by Owner and then by Stage, you see each owner with stages nested beneath. If you reverse the order, you see each stage with owners nested beneath. The same records and the same totals appear, but the first grouping controls how you read the report. Choose the first grouping to match the question you ask most often.
A report can show the lowest-level rows or hide them. The Show Details and Hide Details toggle controls this. With details hidden, you see only group headers and their subtotals. This is the usual setting for a chart source or a dashboard component, because it removes the row-level noise.
Grouping by dates
Date groupings need an extra choice. A date field holds a specific day, so grouping by the raw value gives you one group per distinct day. That is rarely useful. The Group Dates By setting lets you choose a larger unit.
Common granularities include:
- Day
- Week
- Month
- Calendar Quarter
- Calendar Year
- Fiscal Quarter
- Fiscal Year
- Month in Year or Day in Month, which pool the same unit across years
Two choices are easy to confuse. Calendar Month keeps January 2025 and January 2026 as separate groups. Month in Year combines every January into a single group. Use the first to see a time trend. Use the second to see seasonality.
Fiscal options depend on your org's fiscal year settings. If the org uses a custom fiscal year, the group boundaries follow it, not the calendar. Check these settings before you present quarterly numbers to a finance audience.
Blank values
Records with no value in the grouping field are not dropped. They form a group labelled with a dash (-). This is easy to miss. A grouping on Industry will show an extra "-" group for accounts with no industry, and that group has its own count and totals.
Treat this group as a data quality signal. A large "-" group means the field is not filled in consistently. You can leave it in, filter it out with a "not equal to blank" condition, or fix the data. If you hide it, say so, because the totals then no longer cover every record in scope.
Sorting groups
By default, groups sort ascending on the group value. Text sorts alphabetically, dates chronologically, and picklists usually follow their alphabetical value, not the order defined in the picklist. That default can look odd for stages, where "Closed Won" would appear before "Prospecting".
You can change the sort direction for each grouping from its menu in the Outline panel. In Lightning, you can also choose to sort by a summarized value, such as the sum of Amount. That puts your biggest groups first, which suits "top 10" style reports. If you need a business sequence, such as Prospecting through Closed Won, a bucket field is often more reliable than the default sort.
Subtotals and what they mean
Groupings are what give summaries somewhere to appear. Every group header can show a subtotal for each summarized field. These include sum, average, minimum, maximum, and Record Count. The next chapter covers choosing them in detail. Two behaviors are worth knowing now.
- Subtotals at each level are calculated from the records in that group, not from the subtotals beneath it. An average subtotal for an owner is therefore the average of all that owner's opportunities. It is not the average of the owner's stage averages.
- The grand total at the bottom is calculated across all records in the report. Like the subtotals, it is not built from the group-level results.
This matters for averages. Two groups with averages of 10 and 30 do not give a combined average of 20 unless they have the same number of records.
The same idea in SOQL
If you write queries as well as reports, a row grouping corresponds to a GROUP BY clause. The following query returns one row per stage, with a total and a count. These are the same numbers a summary report grouped by Stage would show in its subtotals.
SELECT StageName, SUM(Amount) total, COUNT(Id) cnt
FROM Opportunity
GROUP BY StageNameThe comparison is not exact. A report adds group headers, a grand total, and "-" groups for blank values. The report builder also applies the running user's record visibility. A query run in system context may return different numbers.
Common errors
- Grouping by the wrong field first. The report works but is hard to read. Reorder the groupings in the Outline panel instead of rebuilding the report.
- Grouping a date field without choosing a granularity. You get one group per day. Set Group Dates By to a month, quarter, or year.
- Reading the "-" group as an error. It is the set of records with no value in the grouping field.
- Expecting more than three row groupings in a summary report. The limit is fixed. If you need more dimensions, consider a matrix report or a bucket field that combines categories.
- Expecting a grouped report to list every row. A report shows a limited number of detail rows, so large groups may be cut off in the detail view. The group subtotals still cover all records that match. Add filters or hide details if you need the whole picture.
Worked example
Suppose the sales director asks: "How much open pipeline does each owner have, by close quarter?"
- Start from the Opportunities report type and set the scope to the relevant team.
- Add a filter for open opportunities.
- Group rows by Opportunity Owner.
- Add a second grouping on Close Date, set to Calendar Quarter.
- Summarize Amount as a sum and show Record Count.
- Sort the owner grouping by the sum of Amount, descending.
The result shows each owner with a quarterly breakdown beneath, and the biggest pipeline appears first. If the director then wants owners side by side across quarters, you move Close Date from the row groupings to the column groupings. That change turns the report into a matrix.
Exercise
You group an Opportunities report by Close Date and see hundreds of groups, one per day. What setting do you change, and what does choosing "Month in Year" do differently from "Calendar Month"?
Show answer
Change Group Dates By on the Close Date grouping. Calendar Month keeps each month of each year as a separate group, such as January 2025 and January 2026. Month in Year combines the same month from all years into a single group, which shows seasonality instead of a time trend.
Exercise
A summary report grouped by Industry shows a group labelled "-". What does it contain, and what are two ways to handle it?
Show answer
It contains the records with no value in Industry, and it has its own count and subtotals. You can fix the data so the field is filled in, or add a filter that excludes blank Industry values. If you exclude them, note that the totals no longer cover every record in scope.
Exercise
What is the maximum number of row groupings in a summary report, and how many row and column groupings can a matrix report have?
Show answer
A summary report allows up to 3 row groupings. A matrix report allows up to 2 row groupings and up to 2 column groupings.