Sub topic 1
What Grouping Does and Where to Find It
Prerequisites
This chapter assumes you can do the following:
- Move around Excel and enter basic formulas.
- Keep source data in a table or contiguous range with one header row.
- Create a PivotTable and place fields in Rows, Columns, and Values.
- Use Sum and Count as value field summaries.
What grouping does
A PivotTable lists each unique value of a field as its own row or column. That is fine for a region field with four regions. It is a problem for an order date field with 900 different days, or a price field with 300 different amounts.
Grouping combines the unique items of a field into larger buckets. The PivotTable then summarizes the Values field once per bucket instead of once per item. Excel can build these buckets in three ways:
| Field type | What you can group by | Example result |
|---|---|---|
| Date | Seconds up to years, including days in multiples | Orders per quarter |
| Number | Equal-width ranges | Orders with quantity 0-9, 10-19, 20-29 |
| Text | Items you pick by hand | North and South combined as "Domestic" |
Grouping happens inside the PivotTable. It does not change your source data. Excel adds a grouped field to the PivotTable's field list and keeps the original field available.
A worked example
Suppose a table named Orders has the columns Order Date, Region, Quantity, and Amount. You build a PivotTable with Order Date in Rows and Sum of Amount in Values. Without grouping, you get one row for every day that has an order.
Now group the dates by Months and Years:
- Click any date in the Row Labels area.
- Right-click and choose Group.
- In the Grouping dialog, select Months and Years. Click OK.
The PivotTable now shows one row per month, nested under each year. The total is the same as before. Only the level of detail has changed.
Where to find the Grouping commands
You can reach grouping from three places. All of them require that you first select an item in the field you want to group.
- Right-click menu. Right-click an item in the field and choose Group or Ungroup. This is the quickest route.
- Ribbon. Select an item in the field, then go to PivotTable Analyze and choose Group Selection, Ungroup, or Group Field. In some versions this tab is called Analyze.
- Keyboard shortcuts. Press Alt+Shift+Right Arrow to group the selection. Press Alt+Shift+Left Arrow to ungroup it.
Which dialog you get depends on the field type and on what you select:
- On a date field, Group opens the Grouping dialog with a list of time units.
- On a number field, Group opens the Grouping dialog with Starting at, Ending at, and By boxes.
- On a text field, you must select two or more items first. Group then creates a group without opening a dialog.
A note on how it works
Excel can group dates and numbers because it stores both as numbers. A date is a serial number, so Excel can sort it into months or years by arithmetic. Text has no such order, so you choose the items yourself. The next chapter covers this in detail, including what happens when a "date" is really stored as text.
What grouping does not do
Grouping covers many cases, but not all. It cannot build fiscal years that start in July, and it cannot create buckets of uneven width. For those cases you add a helper column to the source data. A later chapter shows how.
Exercise
You group an Order Date field by Months and Years. Does this change the values in the Order Date column of your source table? What happens to the Sum of Amount grand total?
Show answer
No. Grouping works only inside the PivotTable, so the source column is unchanged. The grand total stays the same, because the same amounts are summed into fewer, larger rows.
Exercise
You select a single text item, such as "North", and right-click. Why might you not be able to create a useful group, and what should you do first?
Show answer
A text group is built from the items you select, and you need to select two or more. Hold Ctrl, click each item you want to combine, and then choose Group.