Time Estimate

# Compare Groups with PREVGROUPVAL() and PARENTGROUPVAL()

## Learn About Summary Group Functions

Logical functions like IF() check whether a condition is true and return one value if true and another if false. Mathematical functions like SQRT() return a number’s square root. You can also use two powerful summary functions to compare values between groups: PREVGROUPVAL() and PARENTGROUPVAL().

## Measure Values over Time with PREVGROUPVAL()

PREVGROUPVAL() lets you compare a specified grouping against a previous grouping in the report builder, making it a powerful tool for calculating how values change over time. PREVGROUPVAL() is most useful for evaluating report data that you’ve grouped by a date field, such as Close Month or Created Date.

If there’s no previous group in the report, PREVGROUPVAL() returns null (that is to say, it returns nothing; no value). For example, say that your report has 12 groups, January through December. For February, PREVGROUPVAL() returns January. For January, because January is the first group, there is no group before it, so PREVGROUPVAL() returns null.

The formula for PREVGROUPVAL() is written as PREVGROUPVAL(summary_field, grouping_level [, increment]). Let’s look at how it breaks down.

• summary_field is the name of the grouped row or column (like AMOUNT:SUM).
• grouping_level is the summary level (like CLOSE_MONTH).
• [, increment] is the number of rows or columns that constitute each grouping.

The maximum value for the [, increment] field is 12. If an [, increment] isn’t specified, then the summary function automatically uses 1.

For example, let’s say Lance Park wants to know, for each month, the difference in sum of opportunity amount from the previous month in the report. He builds an opportunity report and groups it by Close Month. He then adds this summary formula, remembering to select Specific Groups and Close Month under the Display tab.

`AMOUNT:SUM - PREVGROUPVAL(AMOUNT:SUM, CLOSE_MONTH)`

## Find Proportions with PARENTGROUPVAL()

PARENTGROUPVAL() returns the value of a specified parent group, which is any level above the one on which the formula is evaluated. If a report has only one group (like Lance’s opportunity report grouped by Close Month), then the report grand total values are “above” the one group. The report grand totals are always the most senior group.

The formula for PARENTGROUPVAL() is written as PARENTGROUPVAL(summary_field, grouping_level). Here’s how it breaks down.

• summary_field is the value from the grouped row or column (like AMOUNT:SUM).
• grouping_level is the name of a parent-level value in the report (like GRAND_SUMMARY for the overall total).

Ursa Major has received an alarming influx of cases recently, and Gabriela Livingston, the head of sales operations, wants to get to the bottom of it. She asks Ada Belawa, the company’s product support specialist, to create a case report grouped by type, to find out what percentage of cases belongs to each type. Let’s help Ada build a case report and add a custom summary formula with PARENTGROUPVAL() to tease out this information.

1. Create a case report.
• Click Reports.
• Click New Report.
• From the Choose Report Type menu, search for and select Cases.
• Click Start Report.
2. Group the report by Type. Under Group Rows, from the Add group... lookup, search for and select Type.
3. From the Columns pane in the overview panel, click , then select Add Summary Formula.
4. For Column Name, enter `Percent of Total`.
5. For Formula Output Type, select Percent.
6. In the Formula field, paste `RowCount/PARENTGROUPVAL(RowCount, GRAND_SUMMARY)`.
7. Click Display and then select Specific Groups.
8. Verify that Row Group has Type selected.
9. To verify that the formula is valid for the selected display option, click General and then click Validate.
10. Click Apply.
11. Click Save & Run.
12. Name the report `Case Percentages by Type` and set the Report Unique Name to `CASE_PERCENTAGES_BY_TYPE`.
13. Click Save.

Now the Percent of Total column you created appears in the report and gives Ada a better look at where Ursa Major’s quality control team can focus their efforts next.

## Resources

Keep learning for
free!