# Data analysis - subtotals

## 1. Subtotals

One of the simplest ways to summarise worksheet data is to add subtotals.

**Example:** An analyst is interested in the sales data shown in figure 1, worksheet(1) named `Sales Data 1`

.

This data set is constructed as follows:- row 1 is the header or labels row, and describes the fields in each column. This text data has some labels containing space characters. For example, worksheet column A is labeled `Invoice No`

. The numbers `150100, 150101, 150102, ...`

are in the `Invoice No`

fields. There are 11 fields in total. Each row in the body of the data is one unique record. Some blank or empty cells are OK, but there should be no empty rows or columns in the data set. When you click in a cell within the data, the data set becomes the **Current Region**.

## 2. Subtotals - manual

*Reference:* figure 1 Worksheet: `Sales Data 1`

. Suppose that the Analyst is interested in the sales volume achieved by individual salespersons and intends to add subtotals to the data.

Subtotals can be added manually by:

- Sorting the data set on the Salesperson column - see figure 2
- To sort the data in ascending order, select a cell in the Salesperson column (field)
- Then select the sequence on the ribbon, or
- The shortcut sequence
- The data for Jellison ends at row 18
- Insert a new row at row 19, then use the
**SUM**function, or the**SUBTOTAL**function to summarise the data - Repeat this process for the other salespersons

An easier method is to use the Excel subtotal command. Use of the command is shown in the next three subsections.

## 3. Subtotal command

### 3.1 Subtotals - single

Using the same data sort from figure 2, the data is repeated in worksheet(2) named `Sales data - subtotal 1`

.

Subtotals with the subtotal command:

- Click on a cell in the data set
- Then select the sequence on the ribbon, or
- The shortcut sequence
- This displays the
**Subtotal**dialog box- see figure 3 - Figure 3 - the
**Subtotal**dialog box options - Ⓐ At each change in: select Salesperson from the drop down list, Ⓑ Use function: Subtotal, and Ⓒ Add subtotal to: the three quantity columns - Click OK - to display the list in figure 4

The subtotal command adds groups to the data set, with expand and collapse items in the subtotal panel to the left of the row header item. See figure 4.

- The expand / contract feature is used by clicking on a level in the \(\boxed{1}\), \(\boxed{2}\), \(\boxed{3}\) sequence or a group a , item
- \(\boxed{1}\) - Grand Total
- \(\boxed{2}\) - Salesperson Total
- \(\boxed{3}\) - full detail, or click a level 2 to expand individual
**Salesperson**detail - Click or to expand or contract selected group
- To hide or view the subtotal panel press
**Ctrl+8**

### 3.2 Subtotals - multi

Worksheet(3) named `Sales data - subtotal 2`

.

- To add an Average subtotal to the existing Sum subtotal, Use function: Average, and
- Ⓓ untick Replace current subtotals (figure 5) to prevent the Sum being overwritten
- The result is shown in figure 6 - with 4 levels

### 3.3 Subtotals - nested

Worksheet(4): `Sales Data - subtotal 3`

The AZ↓ sort command can only sort on one field. To setup a nested subtotal, two or more fields need to be sorted. This requires the multi level features of the Sort dialog box - figure 7.

To set up a Salesperson subtotal, with a Transport nested subtotal

- Using the Sort dialog box, Sort by: Salesperson, Then by: Transport
- Set the subtotal for Salesperson - figure 3, then
- Set the subtotal for Transport - untick Replace current subtotals
- The result is shown in figure 8 - with 4 levels

### 3.4 Format subtotals

Any cell formats applied to subtotals, are removed when the subtotals are cleared.

To clear subtotals, click the Remove All button in the Subtotal dialog box.

### 3.5 Copy visible subtotal cells

To copy the visible cells (visible subtotal data)

- Select the data to be copied - the Source
- Press
**F5**to display the**Go To Special**dialog box - Select
**Visible cells only** - Click
**OK** - Press
**Ctrl+C**to copy the source to the clipboard - Select the cell for the target, then press
**Ctrl+V**to Paste.

Note: steps 2 to 4 can be replaced by the **Alt+;** keyboard shortcut (see EXCEL: useful keyboard shortcuts - pdf)

## 4. Subtotal function

The subtotal procedure used the Excel subtotal function

Syntax: SUBTOTAL(function_num,ref1,[ref2],...)

Function_num (includes hidden values) | Function_num (excludes hidden values) | Function |
---|---|---|

1 | 101 | AVERAGE |

2 | 102 | COUNT |

3 | 103 | COUNTA |

4 | 104 | MAX |

5 | 105 | MIN |

6 | 106 | PRODUCT |

7 | 107 | STDEV.S (replaced STDEV in xl2010) |

8 | 108 | STDEV.P (replaced STDEVP in xl2010) |

9 | 109 | SUM |

10 | 110 | VAR.S (replaced VAR in xl2010) |

11 | 111 | VAR.P (replaced VARP in xl2010) |

### 4.1 Using SUBTOTAL for summary statistics

You can use the SUBTOTAL function to indirectly link cell labels to the summary statistic procedure - figure 9.

The example in figure 9 is available on the `Summary Stats`

worksheet - Excel Web App #1

The ListSubTotal array has the values ```
={"average",101,1;"count",102,2;"counta",103,3;"max",104,4;
"min",105,5;"product",106,6;"stdev",107,7;"stdevp",108,8;"sum",109,9;"var",110,10;"varp",111,11}
```

**Download**the Excel file for this module: click the link on figure 1**Published:**17 July 2015**Revised:**Wednesday 25th of March 2020 - 06:19 PM, [Australian Eastern Standard Time (EST)]