Group Dates in an Excel Pivot Table by Month and Year
by Avantix Learning Team | Updated March 7, 2021
Applies to: Microsoft® Excel® 2013, 2016, 2019 and 365 (Windows)
If you have valid dates entered in your source data, you can group by month, year or other date period in a pivot table in Excel. There are two common approaches to grouping by date. You can group by date periods in a pivot table using the Grouping feature (this may occur automatically depending on your version of Excel). Alternatively, you can also create calculations in source data to extract the month name and the year from a date field and use the fields in your pivot table.
Recommended article: How to Delete Blank Rows in Excel Worksheets (Great Strategies, Tricks and Shortcuts)
Do you want to learn more about Excel? Check out our virtual classroom or live classroom Excel courses >
Source data is typically entered vertically with data in columns and field names at the top of each column of data.
Grouping by month and year in a pivot table
The key to grouping by month and/or year in a pivot table is a source field with valid dates (such as OrderDate). Depending on your Control Panel settings on your device, valid dates may be entered as month/day/year, day/month/year or year/month/day (although they can be formatted to appear in other ways).
In Excel 2016 and later versions, if you drag a date field into the Rows or Columns area of a pivot table, Excel will group by date increments by default.
The easiest way to group by a date period is to right-click in a cell in a date field in a pivot table and select the desired grouping increments. You can group dates by quarters, years, months and days. The source data does not need to contain a year, quarter or month name column.
To group by month and/or year in a pivot table:
- Click in a pivot table.
- Drag a date field into the Row or Columns area in the PivotTable Fields task pane.
- Select a date field cell in the pivot table that you want to group. Excel may have created a Year and/or Month field automatically.
- Right-click the cell and select Group from the drop-down menu. You can also right-click a date field in the Rows or Columns area in the PivotTable Fields task pane. A dialog box appears.
- Click the date periods that you want to group by. Select Quarters, Years, Months or Days. You can click on more than one such as Years and Months.
- Click OK.
The Grouping dialog box offers multiple options for grouping by date:
The date field will be grouped and new fields will be added to the field list for the groups (if they didn't exist beforehand).
In the following example, Excel grouped automatically by date periods in the PivotTable Fields task pane. This occurs in 2016 or later versions:
To remove a grouping period for a date field:
- Select a date field cell in the pivot table that has been grouped.
- Right-click the cell and select Group. You can also right-click a date field in the Rows or Columns area in the PivotTable Fields task pane. A dialog box appears.
- Deselect or click the groups you wish to remove.
- Click OK.
To remove all grouping:
- Select a date field cell in the pivot table that has been grouped.
- Right-click the cell and select Ungroup.
Controlling automatic grouping
In Excel 2016 and later versions, dates are grouped automatically if they are placed in the Rows or Columns area of the pivot table. You can turn this setting off or on.
To disable automatic grouping for pivot tables:
- Click the File tab in the Ribbon.
- Click Options. A dialog box appears.
- Click Data in the categories on the left. If you are using an older version of Excel, click Advanced in the categories on the left.
- Select or check Disable automatic grouping of Date/Time columns in PivotTables checkbox.
- Click OK.
Below is the Excel Options dialog box in 365:
If you disable automatic grouping, you can still right-click and group in pivot tables but the groups will not be created automatically when you drag a date field to an area in the pivot table.
Issues with pivot table cache
When you create a pivot table and group using the Group feature, the fields and the groupings are stored in a pivot cache, not in the source data. This can be problematic if you create more pivot tables based on the same pivot cache. This means that all pivot tables that share the same cache, will also share the date groupings.
There is no easy way to see which pivot tables share the same cache in the Excel. You would need to use VBA (Visual Basic for Applications) to find this information.
You can unshare the cache by changing the source data range, but this can be tricky if you have a lot of pivot tables.
Creating date period fields in the source data
Another option is to create fields in the source data that calculate date periods (such as Year and Month). You can use the YEAR and TEXT functions to extract Year and Month from a valid date field.
For example, if you have a date in column A, you could create a calculation to extract the Year in column B and the Month in column C.
To calculate the year in B2 (assuming there is a valid date in A2), enter the following formula and then copy the formula down:
To calculate the month name in C2 (assuming there is a valid date in A2), enter the following formula and then copy the formula down:
If the source data is in an Excel table, it's best to use structured referencing formulas in each row such as =YEAR([@OrderDate]) or =TEXT([@OrderDate],"mmmm") where OrderDate is the name of the field and @ is a specifier to refer to the current row or record.
The benefit of creating the fields in the source data is that you can create a pivot table and then group by these fields in the pivot table simply by dragging them into the Rows or Columns area. You will be able to create other pivot tables that do not include the date grouping.
Another advantage of creating fields in the source data is that you can reuse the date period fields in other reports, formulas or slicers.
The method you choose depends on your needs. We have not used the Power Pivot data model here (which provides another method of grouping by date) but is available only in certain versions of Excel. Also, these methods assume a fiscal year of January to December. You'd need to create other calculations in the source data if you want to sort months by a fiscal year that starts and ends in other months (such as April to March).
Subscribe to get more articles like this one
Did you find this article helpful? If you would like to receive new articles, join our email list.
10 Great Excel Pivot Table Shortcuts
Excel Flash Fill Tricks to Clean and Extract Data (10 Examples)
How to Change Commas to Decimal Points in Excel and Vice Versa (5 Ways)
3 Excel Strikethrough Shortcuts to Cross Out Text or Values in Cells
Microsoft Excel: Intermediate / Advanced
Microsoft Excel: Data Analysis with Functions, Dashboards and What-If Analysis Tools
Microsoft Excel: Introduction to Power Query to Get and Transform Data
Microsoft Excel: New and Essential Features and Functions in Excel 365
Microsoft Excel: Introduction to Visual Basic for Applications (VBA)
Our instructor-led courses are delivered in virtual classroom format or at our downtown Toronto location at 18 King Street East, Suite 1400, Toronto, Ontario, Canada (some in-person classroom courses may also be delivered at an alternate downtown Toronto location). Contact us at firstname.lastname@example.org if you'd like to arrange custom instructor-led virtual classroom or onsite training on a date that's convenient for you.
Copyright 2023 Avantix® Learning
You may also like
Excel XLOOKUP Function (Overview, Syntax + Formula Examples)
The XLOOKUP function is a replacement for Excel's traditional VLOOKUP function (as well as HLOOKUP and INDEX / MATCH functions). It has a new set of arguments and is available in Excel 2021 and 365. It allows you to look up a value from an array in a range or table and return one or more results. One of the primary benefits of XLOOKUP is that it can look up from columns to the left in a data set and return a range.
How to Use Go to Special in Excel to Find, Select, Replace and Format Data
You can use Go To Special in Excel to quickly find and select cells of a specific type within your worksheet. It only selects cells in the current worksheet, not the entire workbook. Go To Special also searches within the selected range if a range has been selected. You can find many useful things using the Go To Special dialog box including formulas, constants, blanks, visible cells and conditional formatting. After you select multiple cells with Go To Special, you can enter data in the selected cells by pressing Ctrl + Enter or by applying formatting.
How to Lock Cells in Excel (3 Ways)
It's easy to lock and protect cells in Microsoft Excel to prevent users from changing data or formulas. This involves a two-step process …
Microsoft, the Microsoft logo, Microsoft Office and related Microsoft applications and logos are registered trademarks of Microsoft Corporation in Canada, US and other countries. All other trademarks are the property of the registered owners.
Avantix Learning |18 King Street East, Suite 1400, Toronto, Ontario, Canada M5C 1C4 | Contact us at email@example.com