You can group and subtotal columns of merged data using the “Group” and “Subtotal” parameters. For more information, see Excel Merge Field Parameters.
In the following example, we demonstrate how to group and subtotal Opportunity Line Items by Product Family.
For Excel to sort the fields properly post merge, sort by the same field on your query or report.
Step 1: Non-Grouped Template
Start with a simple template that displays the non-grouped data.
Template:
![](/composer/files/202407.1.4/salesforce/143198765/143201121/1/1614942105496/gsd1.png)
Output:
![](/composer/files/202407.1.4/salesforce/143198765/143201120/1/1614942105359/gsd2.png)
Step 2: Group by Product Family
Next, modify the merge field that represents the Product Family. Add the parameter to group on that field and to skip a row between Product Family values to make room for a subtotal (in a subsequent step).
Sort your report by the same field you are using as a group. For example, sort the example report by Product Family.
Template:
![](/composer/files/202407.1.4/salesforce/143198765/143201119/1/1614942105210/gsd3.png)
Output:
![](/composer/files/202407.1.4/salesforce/143198765/143201118/1/1614942105069/gsd4.png)
Using the SUBTOTAL9 function as depicted below ensures that each group maintains a subtotal and prevents blank lines from appearing below the merge results.
Step 3: Subtotal on Price
Next, insert a formula to subtotal on Total Price. We added bold formatting to the formula to emphasize it.
The Subtotal function must evaluate the same field on which you are grouping. For example, if the field being grouped on is Product Family, then the group parameter will state &=OppLineItems.Product_Family(Group:Merge, Skip:1)
, and Subtotal will be entered as &=Subtotal9:OppLineItems.Product_Family
.
Template:
![](/composer/files/202407.1.4/salesforce/143198765/143201117/1/1614942104923/gsd5.png)
Output:
![](/composer/files/202407.1.4/salesforce/143198765/143201116/1/1614942104785/gsd6.png)
Notice each subtotal in bold text.
Step 4: Compute Grand Total
Finally, insert a formula to find the grand total of the Price column. Do not use the =SUM function to add this column, as it will include the subtotal values in the result. Instead, we’ll include the Excel formula:
=SUBTOTAL(9, C5:C5)
We also added a label for the total (“Grand Total”) and formatted the values as currency (USD).
Template:
![](/composer/files/202407.1.4/salesforce/143198765/143201115/1/1614942104647/gsd7.png)
Output:
![](/composer/files/202407.1.4/salesforce/143198765/143201114/1/1614942104504/gsd8.png)