Group Dates in an Excel Pivot Table by Month and Year

by Avantix Learning Team | Updated June 25, 2020

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)

Source data is normally 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:

  1. Click in a pivot table.
  2. Drag a date field into the Row or Columns area in the PivotTable Fields task pane.
  3. 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.
  4. 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.
  5. 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.
  6. Click OK.

The Grouping dialog box offers multiple options for grouping by date:

Excel group by dates options for a pivot table.

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:

Excel pivot table task pane with year, quarter or date grouping.

To remove a grouping period for a date field:

  1. Select a date field cell in the pivot table that has been grouped.
  2. 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.
  3. Deselect or click the groups you wish to remove.
  4. Click OK.

To remove all grouping:

  1. Select a date field cell in the pivot table that has been grouped.
  2. 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:

  1. Click the File tab in the Ribbon.
  2. Click Options. A dialog box appears.
  3. 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.
  4. Select or check Disable automatic grouping of Date/Time columns in PivotTables checkbox.
  5. Click OK.

Below is the Excel Options dialog box in 365:

Excel Options dialog box to control automatic date grouping in a pivot table.

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:

=YEAR(A2)

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:

=TEXT(A2,”mmmm”)

If the source data is in an Excel table, it’s best to use structured referencing formulas such as =YEAR([OrderDate]) or =TEXT([OrderDate],”mmmm”) where OrderDate is the name of the field.

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.

Summary

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.

Related

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)

Recommended Microsoft Excel training

Microsoft Excel: Intermediate / Advanced

Microsoft Excel: Data Analysis with Functions, Dashboards and What-If Analysis Tools

Microsoft Excel: Introduction to Visual Basic for Applications (VBA)

VIEW MORE COURSES >

Our instructor-led classroom training courses are delivered at our downtown Toronto location at 1 Yonge Street, Suite 1801 (Toronto Star Building), Toronto, Ontario, Canada (some courses may also be delivered at an alternate downtown Toronto location). Contact us if you’d like to arrange custom training at your office on a date that’s convenient for you.

To request this page in an alternate format, contact us.

Copyright 2020 Avantix® Learning 

You may also like

How to Move a Pivot Table in Excel

How to Move a Pivot Table in Excel

Moving a pivot table is not as simple as moving other objects in an Excel worksheet or workbook. You will typically need to use the Move PivotTable command in the Ribbon to move a pivot table to a different area on a worksheet or to a different sheet in the same workbook.

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 | 1 Yonge Street, Suite 1801 (Toronto Star Building), Toronto, Ontario, Canada M5E 1W7 | info@avantixlearning.ca

Summary
How to Group by Month and Year in a Pivot Table in Excel
Article Name
How to Group by Month and Year in a Pivot Table in Excel
Description
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. 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.
Author
Publisher Name
Avantix Learning Inc.

Pin It on Pinterest

Share This