Sub topic 10
Grouping dates and numeric ranges
This chapter assumes you can create a PivotTable from a flat dataset, place fields in the Rows, Columns and Values areas, and read a summed result. It covers how to roll up dates and numbers into larger buckets, and what goes wrong when grouping fails.
Why group
A PivotTable creates one row for every distinct value in a row field. A Date field with 365 distinct days gives 365 rows. A Units field with 80 distinct counts gives 80 rows. Grouping replaces those many values with a few buckets, such as months, quarters, or bands of 10 units.
Grouping is a property of the PivotTable, not of the source data. The source cells stay unchanged, and you can remove the grouping at any time.
The sample data
The examples use the flat dataset from earlier chapters.
Date,Region,Product,Units,Sales
2025-01-05,East,Widget,10,250
2025-01-12,West,Gadget,4,180
2025-02-03,East,Gadget,7,315
2025-02-14,West,Widget,12,300
2025-03-09,East,Widget,5,125Build a PivotTable with Date in Rows and Sum of Sales in Values. Without grouping you get five rows, one per date.
Grouping dates
Automatic grouping
In recent versions of Excel (Microsoft 365 and Excel 2016 and later), dragging a true date field into Rows often groups it automatically. You may see Months added to Rows, and in some cases Years or Quarters as well. Excel then shows extra fields in the Fields pane, such as Months, Quarters or Years. These are not columns in your source data.
If this happens and you do not want it, use PivotTable Analyze > Group > Ungroup. To stop it from happening in future, open File > Options > Data and select the option that disables automatic grouping of date and time columns in PivotTables, if your version offers it.
Grouping manually
- Right-click any date in the Rows area.
- Choose Group.
- In the Grouping dialog, the Starting at and Ending at boxes are filled from the data. Edit them if you want a fixed range.
- In By, select one or more units: Seconds, Minutes, Hours, Days, Months, Quarters, Years.
- Click OK.
Selecting more than one unit creates a hierarchy. If you select Months and Years, Excel adds both fields. Years sits outside Months, so each month is listed under its year.
Selecting only Months is a common mistake. Excel then combines January 2025 with January 2026 into a single row, because the year is not part of the grouping. Select Years as well whenever your data spans more than one year.
Grouping by days
The Days unit is special. When Days is the only selected unit, the Number of days box becomes available. Use it to create buckets such as 7 days for weekly totals.
By: Days
Number of days: 7
Starting at: 2025-01-05Weekly buckets start at the Starting date, not on a Monday. If you want weeks that begin on Monday, set Starting at to a date that is a Monday. In the sample data, 2024-12-30 is a Monday. When Days is selected together with another unit, the Number of days box is disabled and groups are one day long.
Fiscal years
The Grouping dialog uses calendar months and quarters. It has no option to change the fiscal year start. To report by fiscal period, add a helper column to the source data and group by that instead:
=IF(MONTH([@Date])>=7, YEAR([@Date])+1, YEAR([@Date]))This formula assumes a fiscal year that starts in July and is named after the year in which it ends. It uses the structured reference [@Date], so it belongs in an Excel Table. A row dated 2025-08-10 returns 2026. Add the new column to the Table, refresh, and use it as a normal row field.
Grouping numbers
Numeric grouping works the same way, with different boxes.
- Right-click a number in the Rows area, for example a Units value.
- Choose Group.
- Set Starting at, Ending at and By.
By is the width of each bucket. With Starting at 0, Ending at 20 and By 5, the sample data falls into these bands.
| Band | Units values included | Rows |
|---|---|---|
| 0-4 | 4 | 1 |
| 5-9 | 5, 7 | 2 |
| 10-14 | 10, 12 | 2 |
Bands include the lower edge and exclude the upper edge. A value of exactly 5 belongs to 5-9, not 0-4. Excel only lists bands that contain data, so the 15-19 band does not appear here.
Numeric grouping is useful for age bands, order-size bands and price ranges. For uneven bands, such as 0-9, 10-99 and 100+, the Grouping dialog cannot help. Add a helper column in the source data with a lookup formula, or select individual items and group them by hand.
Grouping text items manually
You can also group text items. Select two or more items in the Rows or Columns area (hold Ctrl to select non-adjacent items), right-click, and choose Group. Excel creates a new field named Region2 (or similar) with names such as Group1.
Rename the group by typing over its label. This is useful for combining regions into territories. The grouping is stored in the PivotTable. A new item added to the source later does not join an existing group automatically, and appears separately until you group it.
Ungrouping
Select a grouped item and choose PivotTable Analyze > Ungroup, or right-click and choose Ungroup. For dates, one ungroup action removes all of the date units at once. After ungrouping, the extra fields such as Months and Years disappear from the Fields pane.
How grouping depends on refresh
The following diagram shows how a grouped PivotTable is rebuilt after the source changes.
Existing groups keep their settings through a refresh. Fixed Starting at and Ending at values do not change. If you leave them on automatic, Excel recalculates them from the data, so new dates outside the old range can appear.
When grouping fails
Grouping is the feature most sensitive to dirty data. Common failures:
- "Cannot group that selection." The field contains a blank cell, text, or an error. For a date field, one text entry such as
n/ais enough. For a number field, a blank is enough. Fix the source and refresh. - Dates that look right but will not group. The cells are text, not true dates. A text date is usually left-aligned, and the field is treated as text. Convert them with Data > Text to Columns, or with
=DATEVALUE(A2)in a helper column. - Group is greyed out. The PivotTable was built from the Data Model (the "Add this data to the Data Model" option). Date grouping is handled differently there. Use the automatic date fields, or add a calendar table.
- Grouped items stay after a source edit. Manual text groups keep their old items. Ungroup and group again.
- Unexpected extra fields. Automatic date grouping added Months or Quarters. Ungroup, or drag the unwanted fields out of the Fields pane.
Choosing between grouping and helper columns
| Need | Use grouping | Use a helper column |
|---|---|---|
| Months, quarters, years | Yes | Not needed |
| Weekly buckets | Yes, with days | Only for week-of-year labels |
| Fiscal periods | No | Yes |
| Equal-width numeric bands | Yes | Not needed |
| Uneven numeric bands | No | Yes |
| Grouping that survives Data Model use | No | Yes |
| Labels you control exactly | Limited | Yes |
Helper columns add work to the source but behave predictably, and they are easy to audit. Grouping is faster to set up and easier to change.
Exercise
A PivotTable has Date in Rows, and the data covers January 2025 to December 2026. You group the dates by Months only. January totals look twice as large as expected. What happened, and how do you fix it?
Show answer
With only Months selected, Excel combines the same month from different years, so January 2025 and January 2026 fall into one row. Right-click a date, choose Group, and select both Months and Years. Each month is then listed under its own year.
Exercise
You try to group a Date field and get "Cannot group that selection." Every date looks correct. Name two likely causes and one way to find the problem cells.
Show answer
Likely causes are a blank cell in the Date column, or dates stored as text. To find them, filter the source Date column for Blanks, or sort it so that text entries cluster together, since text sorts apart from true dates. Fix the cells and refresh the PivotTable.
Exercise
Units values are 4, 5, 7, 10 and 12. You group by Starting at 0, Ending at 20, By 5. Which band does the value 10 fall into?
Show answer
It falls into 10-14. Each band includes its lower edge and excludes its upper edge, so 10 starts the third band and is not part of 5-9.