Excel PivotTable Grouping

Mynda Treacy

March 26, 2013

Battling to consolidate monthly figures into quarters, or segment data into numeric bands?

Perhaps you're aiming for a bespoke grouping in your PivotTables.

PivotTable grouping lets you intuitively classify dates, times, and number intervals, while also allowing for tailored group creations to reveal the hidden narratives in your data.

 

What is PivotTable Grouping?

PivotTable grouping enables users to categorize data into specific groups, making it easier to analyze and derive insights.

Instead of sifting through individual data points, you can view summarized data based on your grouping preferences.

 

Watch the Video

Subscribe YouTube

 

Download Workbook

Download an Excel workbook with the examples in this post.

Enter your email address below to download the sample workbook.

By submitting your email address you agree that we can email you our Excel newsletter.

 

Preparing Your Data for Grouping

Before diving into grouping, ensure your data is clean—remove blank cells, ensure consistent data types in each column, and double-check for valid dates. i.e. Dates must be in a date serial number format.

PivotTables also require your data to be formatted in a tabular format where there is a separate column for each field, like the example below:

Example of tabular data in Excel

Use Power Query to unpivot your data if required.

Accessing the Grouping Feature in Excel

To access the grouping feature: Right-click an item in the field you wish to group > Select 'Group' from the menu:

Accessing the grouping feature for a pivot table

Group Dates and Time

With PivotTable grouping we can quickly sum monthly data into quarterly and yearly summaries, and easily segment time-based data into specific time intervals.

For example, accountants often need to summarize monthly data into quarters or years, and Grouping by Days of the Week enables retail and service industries to analyze data based on specific days.

Grouping dates and times

Grouping Numbers into Intervals or Bands

We can easily create numeric intervals, for example, group sales or other numbers into defined ranges like 1-10, 11-20, etc.

And segment data into bands: for instance, classify customers into bands based on their purchase amounts. Or employees into age bands as shown here:

Grouping data into bands

 

Custom Groups

Want to group data that doesn't fit traditional categories? Create your custom groups to tailor your analysis to your needs.For example, you can group specific row/column labels together, which is especially useful for categorical data.

To create a custom group, select the items you want to group > right-click > Group:

Grouping data into custom groups

The new group has the default name: Group1.

Rename it by typing over the text in the cell (E9) and then give the field a new name via the PivotTable Analyse tab:

Rename group and field

This adds a new field to the PivotTable which I’ve renamed: ‘Creatures’ and you can see in the image below that it appears as a new field in the field list.

I’ve also renamed Group1, ‘Magical Beings’ by typing over ‘Group1’ in PivotTable cell E9.

New custom grouping shown in pivot table field list

Continue adding groups as required. And because this is now a new field, I can add a Slicer for it:

Add slicer for new custom Group

Custom Group Gotchas: any other PivotTables based on the same source data (that share the pivot cache) will also have these custom groups added, but they won’t pick up the group names you manually type into the cells of the PivotTable.

You will need to repeat the name labels for each PivotTable individually or copy the one you’ve changed and rebuild the others.

Grouping Cross-tabular Data

Accountants in particular love working with cross-tabular data, like the example below where the dates run across the columns and the items or categories listed down the rows.

Watch this video to see the problems you’ll encounter when you try to Pivot data in this format. Spoiler, it’s a train wreck.

To fix this, first we need to unpivot the data using Power Query, as shown in the video at the top of this page.

Unpivoting cross-tab data

We can then build a PivotTable that groups the data by quarters and Item, and sums the Amount column:

Build pivot table using grouping by quarters

When working with dates in PivotTables, Excel will automatically group them when they’re used in row or column labels.

To modify the default grouping, right-click on the date field in the PivotTable > Group:

Modify default pivot table groupings

In the Grouping dialog box, choose the groups you want:

Choose the groupings you want

Tip: if your data spans multiple years, include ‘Years’ in the grouping.

You’ll see these fields are added to the PivotTable field list for use in your reports:

Chosen groups are added to pivot table field list

PivotTable Grouping Limitations

PivotTable grouping in Excel offers powerful capabilities, but it does come with certain restrictions and considerations:

  1. Blank Cells: If there are any blank cells in the column you're trying to group, Excel will throw an error. You'll need to either fill or remove blank cells before grouping.
  2. Mixed Data Types: Grouping won't work if your column has mixed data types, such as a combination of text and numbers.
  3. Date Grouping: When grouping by dates, the data must be valid date serial numbers. If there are invalid dates or non-date entries like text, the grouping will fail.

    Dates must not include text

  1. Grouping Shared Field: If you group a field in one PivotTable, and if that field is also present in another PivotTable, the second table will also get grouped. This happens because both PivotTables share the same pivot cache.
  2. Manual Groups: If you're creating manual or custom groups, you can't use the usual calculated field or item capabilities in PivotTables and will see an error like this:

    Can't add calculated item to grouped filed

  3. If you need calculated fields and items in your PivotTable and you get this error, then add a field to your source data that enables you to group the data the way you want without having to use the PivotTable Grouping tool. e.g. if you want to group your dates by month, add a Month column to the source data.

  1. Grouping on External Data: Depending on the source of external data, you might encounter limitations or extra steps when trying to group data. For instance, when connecting to OLAP sources, the grouping has to be defined in the cube itself and not in the Excel PivotTable.

Next time you need to summarize data into groups, instead of doing it the hard way with formulas, use PivotTable grouping to make your life easier.

Get started with PivotTables with my Excel PivotTable Quick Start course.

Pivot Table Course

 

12 thoughts on “Excel PivotTable Grouping”

  1. This was awesome, but I have a question. I look at the numeric groups example and I tried to duplicate it. I do exactly the same pivot from the same data source, but when I click on the Age column to group it into buckets I get an error: “Cannot group by that selection.” If I go to your pivot, it works… I can’t tell why?? I can see that there is no data in that column that is not a number so it still doesn’t work… Very strange. Thank you!

    Reply
  2. Hi Mynda,

    I want thank you for sharing the may ways of utilizing Microsoft Excel. I am particularly interested in Pivot tables. Exel recognizes Quarters beginning in January of a year. In my location, the Quarter begins in April. How do I use Excel to recognize Quarter 1 beginning in April?

    Reply
  3. Hi Mynda,

    Now I realise that grouping the dates is not what I’m after, I need to see my list of dates but have a subtotal by month. When I select sub-total I get a total for each date and not a total of all the spends in June and July.
    Is there a way around this?

    tnx

    Reply
    • Hi Tracy,

      Please post your question on our Excel forum where you can upload a sample Excel file with your data and a mock up of your desired solution so we can see what you want and help you further.

      Mynda

      Reply
  4. HI Mynda,

    I have fixed it – I added a total row at the end of my data which created a blank cell in the dates column. Removed the row and now all happy days.

    tnx

    Reply
  5. Hi Mynda,

    My source data is definitely in date format – I get sum, average in the bar below. However, when I click on a date and select group, I get “cannot group that selection”. Any ideas?

    tnx

    Reply
  6. Thank you for your vedio of pivot table presentation. your sound is clear but vedio charecter too small so kindly guide to me how to display screen in Big charecter.

    Thanks again for presentation. Its help for me.

    Kind regards

    Suman

    Reply
    • Hi Suman,

      You can watch the video in full screen. Simply start playing the video and then click on the ‘Full Screen’ icon in the bottom right hand corner of the video screen.

      Kind regards,

      Mynda.

      Reply

Leave a Comment

Current ye@r *