Sub topic 9
Building a matrix report
A matrix report groups records by rows and by columns. Each cell in the grid holds a summary for one row group and one column group. This chapter assumes you can already build a summary report with one row grouping and a summary field such as sum of Amount. It also assumes you know how filters and report types work.
What a matrix adds to a summary report
A summary report answers "how much per X?" A matrix answers "how much per X and Y?" Both come from the same data. The difference is that a matrix adds a second dimension across the top.
Take Opportunities. A summary report grouped by Stage shows one total per stage. A matrix with Stage as rows and Close Year as columns shows one total for each stage and year combination. It also shows row totals, column totals, and a grand total.
| Format | Groupings | Typical question |
|---|---|---|
| Summary | Rows only (up to 3 levels) | Total Amount by Stage |
| Matrix | Rows and columns (up to 2 each) | Total Amount by Stage and by Close Year |
Build the report step by step
- In Lightning Experience, open the Reports tab and choose New Report.
- Pick the Opportunities report type and select Start Report.
- Set the filters first. For example, set Range to a date window on Close Date and keep Show Me on All opportunities. Narrow data keeps the grid readable.
- Open the Outline pane and change the Format to Matrix.
- Drag Stage into the row grouping area.
- Drag Close Date into the column grouping area and set its Group Dates By option to Calendar Year.
- Add the summary field Sum of Amount. Also keep Record Count.
- Run the report and check that the grand total matches the total from a plain tabular version with the same filters.
Rows, columns, and cells
Rows and columns are both groupings. The same grouping rules apply to each:
- Each grouping field can be a picklist, date, text, or lookup field.
- Date fields can be grouped by day, week, month, quarter, or year, in either calendar or fiscal form.
- Groups are sorted ascending by default. You can change the sort for rows, and you can sort by a summary value.
A cell contains the summary of every record that matches both its row value and its column value. If a cell has no matching records, it shows a dash. That means "no records", which is different from a sum of zero.
Multiple summary fields
You can add more than one summary field, for example Sum of Amount and Average of Amount. In a matrix, each cell then shows several values stacked. Totals scale with the number of summaries, so a matrix with four summaries and many columns becomes hard to scan.
Some practical limits help:
- Keep summaries to one or two per matrix.
- Keep column groupings to a small set of values, such as years or quarters.
- Use Show Details only for spot checks. A matrix hides detail rows by default, and that is usually the point.
Two levels on each axis
A matrix supports up to two groupings on rows and up to two on columns. A second row grouping nests inside the first. For example, Stage then Owner on rows.
This multiplies the number of cells. With 6 stages, 10 owners, 4 quarters, and 3 product families, the grid can reach 6 × 10 rows and 4 × 3 columns. That is 60 rows by 12 columns, or 720 cells. Most of the cells will be empty. Prefer one grouping on each axis unless the question needs more.
Summarize with formulas
A custom summary formula works on the numbers in a grouped report. It can show a ratio or a difference. Two formulas from this tutorial's examples:
AMOUNT:SUM / RowCountThis returns the average opportunity amount in each group, calculated as summed Amount divided by record count. In a matrix, the formula is evaluated for each cell and for the totals. The total uses the combined numbers, not the average of the averages.
AMOUNT:SUM - PREVGROUPVAL(AMOUNT:SUM, CLOSE_DATE)This shows the change in summed Amount against the previous group. PREVGROUPVAL needs a grouping to look back along, so it fits best when Close Date is a grouping. The next chapter in the plan covers formulas in more detail.
When you add a formula in a matrix, you choose where it appears. You can show it at all summary levels, or only at specific groupings such as the grand total. Check the setting if the numbers look wrong at the totals.
Buckets and matrix columns
A bucket field groups values into categories without creating a custom field. Buckets work as groupings in a matrix. For example, you could bucket Amount into Small, Medium, and Large and use the bucket as the column grouping. Stage rows against size columns then show where large deals sit in the pipeline.
Remember that a bucket belongs to the report. Other reports cannot reuse it unless you copy it.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Many empty cells | Too many values in a grouping | Filter, bucket, or group dates at a coarser level |
| Totals differ from a tabular check | Filters differ between the two reports | Compare filters, scope, and the **Show Me** setting |
| Records with blank values disappear or appear under a dash | The grouping field is empty for those records | Use a bucket or a filter to handle blanks deliberately |
| Formula total looks wrong | Formula is set to the wrong summary level | Edit the formula and change where it displays |
| Report is slow or truncated | Very large data volume | Add stricter filters before adding groupings |
Matrix reports and the underlying query
A matrix is a two-dimensional version of a grouped aggregate. In SOQL, a summary report on Opportunities grouped by Stage looks like this:
SELECT StageName, SUM(Amount) total, COUNT(Id) cnt
FROM Opportunity
GROUP BY StageNameA matrix with Stage as rows and Close Year as columns returns the same cells as this query:
SELECT StageName, CALENDAR_YEAR(CloseDate) yr, SUM(Amount) total
FROM Opportunity
GROUP BY StageName, CALENDAR_YEAR(CloseDate)Each result row from the query is one cell of the matrix. The query does not return row totals, column totals, or the grand total. The report calculates those. This is a useful mental model for checking a report, and it explains why a matrix with a sparse grid has few query rows: only combinations that exist produce a result.
Matrix reports in charts and dashboards
A matrix can feed a chart. Two points matter:
- With one row grouping and one column grouping, charts such as stacked bars and grouped columns can use both dimensions, so the chart shows the same breakdown as the grid.
- With a second grouping on either axis, chart support is limited. Reduce to one grouping on each axis before you plan a chart.
A dashboard component reads the grouped data from the report and shows it with the chosen chart type. If you change the groupings in the report, check each component that uses it.
Choosing a matrix
Choose a matrix when you need to compare two categories at the same time and the answer is a number per combination. Choose a summary report when one grouping is enough, or when you need detail rows visible under each group. Choose a joined report when the data comes from different report types and needs to be shown side by side.
Exercise
A matrix report has Stage as rows and Close Year as columns, showing Sum of Amount. The Prospecting row shows a dash under 2025. Does this mean the Prospecting total for 2025 is zero? Which SOQL query shape would return a row for that cell?
Show answer
No. A dash means no records match that stage and year, so there is nothing to sum. The SOQL query grouped by StageName and CALENDAR_YEAR(CloseDate) returns only combinations that exist, so it returns no row for Prospecting and 2025. A row would appear only if an Opportunity with that stage and year existed.
Exercise
A sales leader wants average deal size for each Stage and each Close Year. You add the formula AMOUNT:SUM / RowCount to a matrix. At the grand total, the value is 48,000. Is that the average of all the cell averages? Explain.
Show answer
No. The formula runs on the combined numbers at that level. At the grand total, it divides the total summed Amount by the total record count. This is a weighted average across all records. An average of cell averages would give each cell equal weight regardless of how many records it contains.