Group Dates by Month or Year in a Pivot Table
By ExcelReady TeamUpdated 5 min read
The short answer
To group dates in a pivot table, put the date field in Rows, right-click any date and choose Group. In the Grouping box, select Months and Years, then click OK. The pivot then shows one total per month, split by year. If Excel says it cannot group the selection, the date column holds blanks or text.
Key takeaways
- Right-click a date in the pivot and choose Group, then pick Months, Quarters, Years or Days.
- Always select Years together with Months, or January of every year is added together.
- For weekly totals, choose Days only and set Number of days to 7.
- Cannot group that selection means the date column has blanks, text or errors.
- Recent Excel versions group dates automatically when you add a date field to Rows.
On this page+
To group dates in a pivot table, right-click a date in the pivot, choose Group, and pick a unit such as Months and Years. Instead of one row per day, you get one total per month, quarter or year, which is what most reports need. This guide covers each grouping option, how to keep years apart, weekly groups, and what to do when Excel refuses to group.
Why group dates in a pivot table?#
A pivot table normally lists every date as its own row. With a year of daily orders, that is up to 365 rows, which is too detailed to read. Grouping rolls the dates up into bigger periods, so the pivot answers questions like "what were sales each month?" in one view.
The examples use this order list in A1:C9:
| A | B | C | |
|---|---|---|---|
| 1 | Date | Region | Sales |
| 2 | 5-Dec-2023 | East | 1200 |
| 3 | 19-Dec-2023 | West | 900 |
| 4 | 8-Jan-2024 | East | 1500 |
| 5 | 22-Jan-2024 | West | 700 |
| 6 | 3-Feb-2024 | East | 1100 |
| 7 | 14-Feb-2024 | East | 600 |
| 8 | 27-Feb-2024 | West | 1300 |
| 9 | 11-Mar-2024 | West | 800 |
If you are new to pivots, build one first with the beginner's guide to pivot tables.
How to group dates by month and year#
Put the date field in Rows and Sales in Values, then follow these steps:
- Right-click any date in the pivot table's row labels.
- Choose Group. (You can also use PivotTable Analyze > Group Field.)
- In the Grouping box, click Months and Years so both are highlighted. Click a selected item again to deselect it.
- Leave Starting at and Ending at as they are, unless you want to cut off early or late dates.
- Click OK.
The pivot now looks like this:
| Row Labels | Sum of Sales |
|---|---|
| 2023 | |
| Dec | 2100 |
| 2024 | |
| Jan | 2200 |
| Feb | 3000 |
| Mar | 800 |
| Grand Total | 8100 |
Excel adds a new Years field to the field list, and the original date field now shows months. You can drag Years to Columns to put the years side by side, which makes month-by-month comparisons easy.
Why you should select Years with Months#
If you choose Months alone, Excel groups by month name only. January 2023 and January 2024 land in the same "Jan" row, and the total mixes both years. That's a common mistake in reports and in interview tasks.
Select Years too whenever the data covers more than one year. With the table above, Months alone would still be correct today, but one more December order from 2024 would silently join the 2023 December row.
The same rule applies to Quarters: choose Quarters and Years together to get Qtr1 2024 rather than every first quarter added up.
How to group dates by week or a number of days#
Weeks aren't in the list, but you can make them from days:
- Right-click a date and choose Group.
- Deselect everything except Days.
- Set Number of days to 7.
- Change Starting at to a Monday (or Sunday) on or before your first date, so each group is a full calendar week.
- Click OK.
Each row now shows a date range in your date format, such as 4 December to 10 December 2023 for the first week. You can't combine a 7-day group with Months or Years; the Number of days box only works when Days is the only unit selected.
Automatic date grouping in newer Excel#
In Excel 2016 and later, including Microsoft 365, dropping a date field into Rows often groups it for you. Excel adds fields such as Years, Quarters and Months and shows the top level with plus buttons to expand.
If you want the plain dates, press Ctrl+Z (Mac: ⌘Z) right after adding the field, or right-click a date and choose Ungroup. In Excel for Windows, you can switch the feature off under File > Options > Data with the option to disable automatic grouping of date and time columns in PivotTables.
One more thing to know: pivots built from the same source share their grouping. If you group dates in one pivot, a second pivot from the same data shows the same groups.
Why does Excel say "Cannot group that selection"?#
This message means at least one item in the date field isn't a real date. Excel can only group a field when every value is a date or a number. Check the source data for:
- Blank cells. A single empty date cell is enough. Fill it in, or remove the row.
- Text dates. Dates typed as text, often from an import, sit on the left of the cell. Convert them with Data > Text to Columns or DATEVALUE.
- Error values such as #VALUE! in the date column.
- A source range with empty rows. If the pivot's range runs past the data, the empty rows count as blanks. Use an Excel table as the source so the range fits exactly.
After fixing the data, refresh the pivot (right-click > Refresh), then try Group again.
Can you group dates without a pivot table?#
Yes. A formula gives the same monthly totals and updates without a refresh. For February 2024, with 1-Feb-2024 in E2 and 1-Mar-2024 in E3:
=SUMIFS(C2:C9,A2:A9,">="&E2,A2:A9,"<"&E3)The result is 3,000, the same as the pivot. Using "before 1 March" rather than "on or before 29 February" also catches dates that include a time. The comparison of pivot tables vs SUMIFS explains when each is better. After grouping, you can also show each month as a share of the year with percent of total in a pivot table, add a ratio with a calculated field, or filter months by clicking with slicers and timelines.
Practise it#
Grouping by month is one of the first things an interviewer asks you to do with a pivot, so it pays to be fast. Practise pivot tables in a live spreadsheet: nest row fields, add filters and percent of total, and check your answers instantly. If you're preparing for an interview, review the most common pivot table interview questions too.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
Check the pivot's February 2024 total with a formula. In F2, use SUMIFS to add C2:C9 where the date in A2:A9 is on or after E2 and before E3.
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Sales | Feb 2024 sales | |||||
| 2 | |||||||
| 3 | |||||||
| 4 | |||||||
| 5 | |||||||
| 6 | |||||||
| 7 | |||||||
| 8 | |||||||
| 9 | |||||||
| 10 | |||||||
| 11 | |||||||
| 12 |
Tip: Sum C2:C9. First test: A2:A9 with ">="&E2. Second test: A2:A9 with "<"&E3.
Practise this in a lesson
Frequently asked questions
How do I group dates by month in a pivot table?
Right-click any date in the pivot table's rows and choose Group. Select Months, and also Years if the data covers more than one year, then click OK.
Why can't I group dates in my pivot table?
At least one cell in the date column is blank, text or an error, so Excel can't treat the field as dates. Fix those cells in the source data, refresh the pivot and try Group again.
How do I group dates by week in a pivot table?
Right-click a date, choose Group, deselect everything except Days and set Number of days to 7. Change Starting at to a Monday if you want Monday-to-Sunday weeks.
How do I stop a pivot table from grouping dates automatically?
Press Ctrl+Z straight after adding the field to undo the grouping, or right-click a date and choose Ungroup. In Excel for Windows you can turn it off under File > Options > Data.
How do I ungroup dates in a pivot table?
Right-click any grouped date or month label and choose Ungroup. The field goes back to showing each date on its own row.