---
schema_version: "1"
id: ce3a398311c4780e6f34ea40d39699d70637866cb6ba18789d2f53aca3e65bd2
title: PARENTGROUPVAL and PREVGROUPVAL
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/analytics/264-0-0/reports_summary_functions_about.md
canonical_url: https://help.salesforce.com/s/articleView?id=analytics.reports_summary_functions_about.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 99600401e2ec0c0ae05d47b3c150795b3333688ae01cf0a8a68218fba7283233
description: Use PARENTGROUPVAL to calculate values relative to a parent grouping. Use PREVGROUPVAL to calculate values relative to a peer grouping.
products:
  - Cross Cloud
release: "264"
---
# PARENTGROUPVAL and PREVGROUPVAL

Use `PARENTGROUPVAL` to calculate values relative to a parent grouping. Use `PREVGROUPVAL` to calculate values relative to a peer grouping.

## PARENTGROUPVAL

Use this function to calculate values relative to a parent grouping.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
          <colgroup>
            <col style="width:25.5%">
            <col style="width:74.5%">
          </colgroup>
          <tbody>
            <tr class="">
              <td class="slds-cell-wrap" style="vertical-align:top;">
                <strong>Description:</strong>
              </td>

              <td class="slds-cell-wrap" style="vertical-align:top;">
                <span id="reports_summary_functions_about__PARENTGROUPVALDef"><a name="reports_summary_functions_about__PARENTGROUPVALDef"><!-- --></a>This function returns the value of
                  a specified parent grouping. A “parent”
                  grouping is any level above the one containing the formula.
                  You can use this function only in custom summary formulas
                  and at grouping levels for reports, but not at summary
                  levels.</span>
              </td>

            </tr>
            <tr class="">
              <td class="slds-cell-wrap" style="vertical-align:top;">
                <strong>Use:</strong>
              </td>

              <td class="slds-cell-wrap" style="vertical-align:top;">
                <p>
                  <strong>For reports that are grouped by rows (summary) and for
                    joined reports:</strong>
                  <code>PARENTGROUPVAL(summary_field,
                                        grouping_level)</code>
                </p>
                <p>
                  <strong>For reports that are grouped
                    by rows and columns (matrix):</strong>
                  <code>PARENTGROUPVAL(summary_field,
                                            parent_row_grouping,
                                        parent_column_grouping)</code>
                </p>
                <p>Where <code>summary_field</code> is the
                  summarized field value, <code>grouping_level</code> is <code>GRAND_SUMMARY</code> or the API name of the parent
                  level group for summary reports, and <code>parent_row_level</code> and
                  <code>parent_column_level</code> are the parent levels for
                  matrix reports.
                </p>
                <p style="margin-bottom:0;">In reports with multiple grouping
                  levels, you can set the <code>grouping_level</code> to be any group level higher
                  than the formula display level.</p>
              </td>

            </tr>
            <tr class="">
              <td class="slds-cell-wrap" style="vertical-align:top;">
                <strong><span id="reports_summary_functions_about__PARENTGROUPVALExample"><a name="reports_summary_functions_about__PARENTGROUPVALExample"><!-- --></a>Example</span>:</strong>
              </td>

              <td class="slds-cell-wrap" style="vertical-align:top;">
                <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>TOTAL_PRICE:SUM/PARENTGROUPVAL(TOTAL_PRICE:SUM, GRAND_SUMMARY)</code></pre>
                <p style="margin-bottom:0;">This formula calculates, for each product, its relative size
                  compared to the grand total. In this example, the report is
                  a summary of opportunities and their products, grouped by
                  <samp class="parmname">Product Name</samp>.
                </p>
              </td>

            </tr>
          </tbody>
        </table>

## PREVGROUPVAL

Use this function to calculate values relative to a peer grouping. If there's no previous grouping, the function returns a null value.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
          <colgroup>
            <col style="width:25.5%">
            <col style="width:74.5%">
          </colgroup>
          <tbody>
            <tr class="">
              <td class="slds-cell-wrap" style="vertical-align:top;">
                <strong>Description:</strong>
              </td>

              <td class="slds-cell-wrap" style="vertical-align:top;">
                <span id="reports_summary_functions_about__PREVGROUPVALDef"><a name="reports_summary_functions_about__PREVGROUPVALDef"><!-- --></a>This function returns the value of a
                  specified previous grouping. A “previous”
                  grouping is one that comes before the current grouping in
                  the report. Choose the grouping level and increment. The
                  increment is the number of columns or rows before the
                  current summary. The default is 1; the maximum is 12. You
                  can use this function only in custom summary formulas and at
                  grouping levels for reports, but not at summary
                  levels.</span>
              </td>

            </tr>
            <tr class="">
              <td class="slds-cell-wrap" style="vertical-align:top;">
                <strong>Use:</strong>
              </td>

              <td class="slds-cell-wrap" style="vertical-align:top;">
                <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code class=" nolang">PREVGROUPVAL(summary_field, grouping_level [, increment])</code></pre>
                <div>
                  <p>When <code>summary_field</code> is
                    the name of the grouped row or column:</p>
                  <ul>
                    <li><code>grouping_level</code>
                      is the API name of the peer level group whose
                      summary value is used for the previous grouping. </li>
                    <li><code>increment</code> is
                      the number of previous groupings.</li>
                  </ul>
                </div>
                <p style="margin-bottom:0;">In reports with multiple grouping levels, you can specify
                  <code>grouping_level</code> to
                  be either the same group level as the formula display level
                  or a group level higher than the formula display level.
                </p>
              </td>

            </tr>
            <tr class="">
              <td class="slds-cell-wrap" style="vertical-align:top;">
                <strong><span id="reports_summary_functions_about__PREVGROUPVALExample"><a name="reports_summary_functions_about__PREVGROUPVALExample"><!-- --></a>Example</span>:</strong>
              </td>

              <td class="slds-cell-wrap" style="vertical-align:top;">
                <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>AMOUNT:SUM - PREVGROUPVAL(AMOUNT:SUM, CLOSE_DATE)</code></pre>
                <p style="margin-bottom:0;">This formula calculates, for each month, the difference in
                  amount from the previous month shown in the report. In this
                  example, the report is an opportunity matrix with columns
                  grouped by <samp class="parmname">Close Date</samp> and rows by
                  <samp class="parmname">Stage</samp>.
                </p>
              </td>

            </tr>
          </tbody>
        </table>

## Example: Three Week Moving Average

To calculate a three-week moving average of opportunity amounts:

```
(OppProductTrends__c.Amount__c:SUM+ PREVGROUPVAL(OppProductTrends__c.Amount__c:SUM, OppProductTrends__c.as_of_date__c) + PREVGROUPVAL(OppProductTrends__c.Amount__c:SUM, OppProductTrends__c.as_of_date__c,2))/3
```

#### See Also

- [Add a Summary Formula Column to a Report](https://help.salesforce.com/s/articleView?id=analytics.building_custom_summary_formulas.htm&release=264.0.0&type=5 "Before adding a summary formula to your report, be sure to group report data. Summary formula columns require at least 1 group.")
- [Evaluate Groups and Totals with Summary Formulas](https://help.salesforce.com/s/articleView?id=analytics.reports_builder_fields_formulas.htm&release=264.0.0&type=5 "Write summary formulas to evaluate a report's group subtotals and grand totals. For example, summary formulas can adjust earnings after tax.")
- [Add a Summary Formula to a Joined Report](https://help.salesforce.com/s/articleView?id=analytics.reports_joined_custom_summary_formulas.htm&release=264.0.0&type=5 "Summary formulas in joined reports are just like summary formulas in standard reports, except they can apply to multiple blocks or just one. When you add a summary formula to a block, you specify whether it applies across blocks or only to that block.")