How to Group by Month and Year in a Pivot Table in Excel (2023)

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

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:

  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:

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 receivenew 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 2023 Avantix® Learning

Microsoft, the Microsoft logo,Microsoft Office and related Microsoft applicationsand logosare 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

Top Articles
Latest Posts
Article information

Author: Twana Towne Ret

Last Updated: 10/31/2023

Views: 6247

Rating: 4.3 / 5 (64 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Twana Towne Ret

Birthday: 1994-03-19

Address: Apt. 990 97439 Corwin Motorway, Port Eliseoburgh, NM 99144-2618

Phone: +5958753152963

Job: National Specialist

Hobby: Kayaking, Photography, Skydiving, Embroidery, Leather crafting, Orienteering, Cooking

Introduction: My name is Twana Towne Ret, I am a famous, talented, joyous, perfect, powerful, inquisitive, lovely person who loves writing and wants to share my knowledge and understanding with you.