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:

  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 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.

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.

More resources

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

Related courses

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)

VIEW MORE COURSES >

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 info@avantixlearning.ca if you'd like to arrange custom instructor-led virtual classroom or onsite training on a date that's convenient for you.

Copyright 2024 Avantix® Learning

You may also like

How to Replace Zeros (0) with Blanks in Excel

How to Replace Zeros (0) with Blanks in Excel

There are several strategies to replace zero values (0) with blanks in Excel. If you want to replace zero values in cells with blanks, you can use the Replace command or write a formula to return blanks. However, if you simply want to display blanks instead of zeros, you have two formatting options – create a custom number format or a conditional format.

What is Power Query in Excel?

What is Power Query in Excel?

Power Query in Excel is a powerful data transformation tool that allows you to import data from many different sources and then extract, clean, and transform the data. You will then be able to load the data into Excel or Power BI and perform further data analysis. With Power Query (also known as Get & Transform), you can set up a query once and then refresh it when new data is added. Power Query can import and clean millions of rows of data.

How to Freeze Rows in Excel (One or Multiple Rows)

How to Freeze Rows in Excel (One or Multiple Rows)

You can freeze one or more rows in an Excel worksheet using the Freeze Panes command. If you freeze rows containing headings, the headings will appear when you scroll down. You can freeze columns as well so when you scroll to the right columns will be frozen.

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 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

Pin It on Pinterest

Share This