# How do Summary Formulas compute aggregate percentages and ratios across grouped report data?

**Topic:** Admin · **Difficulty:** Medium · **Tags:** Admin, Summary Formulas, Aggregate Calculations

Read it on the site: https://www.forcechallenges.com/interview-questions/how-do-summary-formulas-compute-aggregate-percentages-and-ratios-across-grouped-report-data

## Answer

**Basics:** A row-level calculation works per record; a summary formula works on totals. For example, "Won amount divided by total amount per owner" needs both aggregates, so it must be computed after grouping. You add them in Summary, Matrix and Joined reports (Joined via cross-block formulas); tabular reports do not support them.

**How it works:**
1. In the report builder, Add Summary Formula in the Columns/Outline.
2. Name it, choose the format (Number, Currency or Percent) and decimal places.
3. Choose where it displays: all summary levels, or specific groupings and Grand Total.
4. Write the formula using aggregate fields, for example `AMOUNT:SUM / RowCount`.
5. Apply and optionally add it to charts or conditional highlighting.

**Advanced / deep dive:** Special functions: `PARENTGROUPVAL(summary_field, parent_level)` returns the parent group's value (to compute share of parent or total), and `PREVGROUPVAL(summary_field, group_level)` returns the previous group's value (for period-over-period change). Percent of total: `RowCount / PARENTGROUPVAL(RowCount, GRAND_SUMMARY)`. Because formulas run at each level, an average of averages problem can mislead: dividing sums and counts yourself is safer than relying on summarized averages. Summary formulas cannot be used as report filters and have complexity limits; there is a cap on formulas per report (about 10; verify). They can appear in dashboards and conditional highlighting. Use a divide-by-zero guard such as `IF(RowCount = 0, 0, ...)`. For heavy analytics beyond group-level calculation, consider CRM Analytics (formerly Tableau CRM).

**Code / config example:**
```
// Win rate per owner (Percent format, display at Opportunity Owner level)
IF(RowCount = 0, 0, Opportunity.Won_Count__c:SUM / RowCount)

// Share of grand total amount per group
AMOUNT:SUM / PARENTGROUPVAL(AMOUNT:SUM, GRAND_SUMMARY)

// Change vs previous month (group by Close Date month)
AMOUNT:SUM - PREVGROUPVAL(AMOUNT:SUM, CLOSE_DATE)
```

**Hidden gotchas & must-remember points:**
- Not available on tabular reports.
- Wrong display level gives wrong values; choose the grouping level deliberately.
- `PREVGROUPVAL` requires a date or ordered grouping.
- Division by zero returns errors or blanks unless guarded.
- Percent format multiplies by 100 on display only.
- Summary formulas cannot reference other summary formulas in some cases; keep them simple.

**Best practice:** Compute from underlying sums and counts, guard against zero, and set the display level explicitly.

---
Source: ForceChallenges · last updated 2026-11-02
