Sub topic 9
Building a matrix report
This chapter assumes you can build a summary report with row groupings and summary fields. It also assumes you know how to pick a report type and add filters. You will now add a second grouping dimension across the columns.
What a matrix report adds
A matrix report groups records by rows and by columns. Each cell shows a summary for one row value and one column value. Use it when a business question compares two dimensions, such as "How much revenue did each stage produce in each close year?"
A summary report can group by several fields, but all groupings run down the left side. A matrix puts one grouping across the top, so you can read both dimensions at once.
Build it step by step
- Create a report with the Opportunities report type.
- Set filters first, such as a Close Date range, so the matrix stays readable.
- Switch the format to Matrix, or start from a summary report and change the format.
- Drag Stage into the Rows area.
- Drag Close Date into the Columns area, and set its grouping to Calendar Year.
- Add the summary field Sum of Amount.
- Run the report and check the totals.
The report shows row totals on the right, column totals at the bottom, and a grand total in the corner. The row and column totals are calculated from the underlying records. They are not sums of the cells you see, which matters for averages.
Choosing summaries in a matrix
A matrix applies the same summary fields to every cell. If you add Sum of Amount and Record Count, each cell shows both values. Keep the list short, because every extra summary multiplies the numbers in every cell.
Averages in totals are calculated from all records in that row or column. They do not average the cell averages.
Formulas in a matrix
Custom summary formulas work in a matrix. This formula gives the average opportunity amount in each cell:
AMOUNT:SUM / RowCountA formula can also be shown at selected grouping levels, so check where it appears before you trust the totals.
The same numbers in SOQL
A matrix is a two-dimension aggregate. This query returns the cells of the Stage by Close Year matrix:
SELECT StageName, CALENDAR_YEAR(CloseDate) yr, SUM(Amount) total
FROM Opportunity
GROUP BY StageName, CALENDAR_YEAR(CloseDate)The query returns one row per Stage and year pair. The report lays those pairs out in a grid.
Common errors
- Too many column values. Grouping by a field with many distinct values, such as Account Name, makes the matrix wide and hard to read. Use a field with few values, or a bucket field.
- Empty cells read as zero. A blank cell means no records matched. It does not mean the summary was zero.
- Wrong date granularity. Grouping Close Date by day produces one column per day. Choose Calendar Month, Quarter, or Year.
- Filters hide the answer. If a total looks low, check the filters and the report scope, such as "My opportunities" versus "All opportunities."
Exercise
A matrix report has Stage as rows and Close Year as columns, with Sum of Amount as the summary. The 2025 column total differs from what you get by adding the visible 2025 cells. What is the most likely explanation?
Show answer
Some records are not shown in the visible cells, for example because of a stage you removed from the view or a hidden grouping value. The column total is calculated from all records in the filtered result, so it reflects every record that passed the filters. Check the filters and the grouping values.
Exercise
Write the SOQL aggregate query that returns the same cells as a matrix with Stage as rows and Close Year as columns, showing Sum of Amount.
Show answer
SELECT StageName, CALENDARYEAR(CloseDate) yr, SUM(Amount) total FROM Opportunity GROUP BY StageName, CALENDARYEAR(CloseDate)