Sub topic 3
Grouping dates by months, quarters, and years
This chapter assumes you can build a PivotTable from a table or contiguous range with one header row. It also assumes you can place fields in Rows, Columns, and Values, and that you know Sum and Count as value summaries. Everything here uses the Grouping dialog, which is the main tool for turning daily dates into larger periods.
What grouping does with dates
A PivotTable lists each distinct value of a field as its own row. A date field with a year of daily orders produces hundreds of rows. Grouping collapses those dates into buckets such as months, quarters, or years, so the Values area sums or counts per bucket instead of per day.
Grouping works because Excel stores a real date as a serial number. The number counts days from a starting point, so a date is a number with a date format applied. Excel can therefore compute which month, quarter, or year a number falls in. Text that only looks like a date has no serial number, so it cannot be grouped. The error section below covers that case.
Grouping is a property of the PivotTable, not of the source data. The source cells stay unchanged, and Excel adds the grouping on top of the field.
A sample data set
The examples use an orders table with an order date, a region, and an amount. You can type a few rows to follow along. The table needs a real date in every row of the date column.
| OrderDate | Region | Amount |
|---|---|---|
| 2024-01-15 | North | 120 |
| 2024-02-03 | South | 80 |
| 2024-04-20 | North | 200 |
| 2024-07-09 | East | 150 |
| 2025-01-28 | South | 95 |
Before grouping, confirm the dates are real dates. In a blank cell beside the first date, enter this formula and fill it down.
=ISNUMBER(A2)A result of TRUE means the cell holds a real date or number. FALSE means the cell holds text, and that row will block grouping.
Grouping a date field step by step
- Select any cell in the source table and choose Insert, then PivotTable.
- Drag OrderDate to Rows and Amount to Values. The Values area shows Sum of Amount.
- Right-click any date in the Rows area and choose Group.
- In the Grouping dialog, the Starting at and Ending at boxes show the earliest and latest dates in the data. Leave them as they are.
- In the By list, select Months and Years. Click each entry to toggle it on or off.
- Click OK.
The Rows area now shows years, and each year expands to its months. In newer versions of Excel, the field list also gains a new field named Years next to OrderDate.
The By list offers these units:
| Unit | Result |
|---|---|
| Seconds, Minutes, Hours | Time-of-day buckets, used only when the field contains times |
| Days | One bucket per day, with an option for a number of days |
| Months | Twelve buckets named Jan to Dec, shared across years unless Years is also selected |
| Quarters | Qtr1 to Qtr4, shared across years unless Years is also selected |
| Years | One bucket per calendar year |
Selecting several units at once
You can select more than one unit. Excel nests them from the largest to the smallest in the order Years, Quarters, Months, Days.
The choice of units changes the result in a way that surprises many people. Consider selecting Months alone. January 2024 and January 2025 land in the same Jan row, and their amounts are added together. This is correct when you want a seasonal view, and it is wrong when you want a timeline.
Selecting Years and Months together keeps January 2024 and January 2025 separate. Each year becomes its own group, and the months sit inside it.
Selecting Years, Quarters, and Months creates three levels. The table below shows what each choice does with the sample data.
| Units selected | Rows shown | January 2024 and January 2025 |
|---|---|---|
| Months | Jan, Feb, Apr, Jul | Combined in one Jan row |
| Years, Months | 2024 then months, 2025 then months | Separate |
| Years, Quarters | 2024 then Qtr1, Qtr2, Qtr3; 2025 then Qtr1 | Separate |
| Years, Quarters, Months | Three nested levels | Separate |
Showing groups side by side
Each level works like any other field. You can collapse a year with its minus button to see only totals per year. You can also move the Years field from Rows to Columns to place years across the top and months down the side. This layout compares the same month across years directly.
Automatic date grouping in newer Excel versions
Newer versions of Excel group dates for you. When you drag a date field into Rows or Columns, Excel may immediately show Years, Quarters, and Months instead of individual dates. This is called automatic date grouping.
It can help for quick exploration, but it can also get in the way. You may want the plain dates, or you may want a different grouping than the default one.
You have two ways to deal with it.
- Undo the grouping for one PivotTable. Right-click a date in the Rows area and choose Ungroup. The next section covers this.
- Turn the feature off for all new PivotTables. Go to File, Options, Data. Under Data options, select "Disable automatic grouping of Date/Time columns in PivotTables." Then click OK.
The setting applies only to PivotTables you create afterward. Existing ones keep the grouping they already have.
Reading the quarter labels
Excel labels quarters Qtr1 to Qtr4 and always starts Qtr1 in January. The Grouping dialog has no setting to change that. If your organization has a fiscal year starting in another month, the dialog cannot produce it. A helper column in the source data solves this, and the next sections show the formulas.
Helper columns for fiscal periods
A helper column is an extra column you add to the source data. It computes the label you want for each row. You then refresh the PivotTable and use the new column as a field.
For a fiscal year that starts in July and is named after the calendar year in which it ends, use this formula.
=YEAR(A2)+(MONTH(A2)>=7)The comparison MONTH(A2)>=7 returns TRUE or FALSE. Excel treats TRUE as 1 in arithmetic. A date in August 2024 returns 2025. A date in March 2024 returns 2024.
For the matching fiscal quarter label, use this formula.
="Q"&(INT(MOD(MONTH(A2)-7,12)/3)+1)MONTH(A2)-7 shifts July to 0. MOD(...,12) wraps earlier months to positive values, so January becomes 6. Dividing by 3 and taking INT gives 0 to 3, and adding 1 gives Q1 to Q4. July through September give Q1, and April through June give Q4.
Put the fiscal year in Rows and the fiscal quarter beneath it. Because these are ordinary text and number columns, no grouping is needed.
Why grouped dates still follow the data
The grouping stays attached to the field when you refresh. If you add rows with new dates inside the existing range, they fall into the right buckets. Dates outside the Starting at and Ending at values need care, because the range was fixed when you created the grouping. Later chapters cover refresh behavior in more detail. For now, remember that a range change may require you to reopen the Grouping dialog and update the start or end date.
Common problems with date grouping
The Group command is unavailable or fails
Selecting Group on a date field can show the message "Cannot group that selection." The usual causes are these.
- A cell in the date column is blank.
- A cell holds text that looks like a date, such as a date entered as "2024-01-15" with a leading apostrophe or imported as text.
- The field header was selected instead of an item.
To locate the offending rows, apply the ISNUMBER formula shown earlier and filter for FALSE. Convert those cells to real dates, or fill the blanks, then refresh and group again.
Months show as names without years
If you see only Jan to Dec, you selected Months without Years. Reopen the Grouping dialog and add Years to the selection.
The groups do not sort in the order you expect
Grouped months and quarters sort by date order, not alphabetically. If you see alphabetical order, the field is probably text rather than a grouped date field.
Practice
Exercise
Your PivotTable shows one Jan row that combines January 2024 and January 2025. You want the two Januaries separate. What do you change in the Grouping dialog?
Show answer
Reopen the Grouping dialog and select Years in addition to Months in the By list. Excel then creates a year level, and each year holds its own months.
Exercise
A fiscal year starts in July and is named after the calendar year in which it ends. What does =YEAR(A2)+(MONTH(A2)>=7) return for 15 September 2024, and why?
Show answer
It returns 2025. The month is 9, so MONTH(A2)>=7 is TRUE, which counts as 1. Adding 1 to 2024 gives 2025.
Exercise
You select a date cell in the Rows area and Group returns "Cannot group that selection." What is the quickest check on the source data?
Show answer
In a helper column next to the dates, enter =ISNUMBER(A2) and fill it down. Any FALSE marks a text value or blank that must be converted to a real date or filled. Then refresh the PivotTable and group again.