Grouping and Totaling
Pivot Table Data
W
hen you add date fields to a pivot table, you can show the dates individually, or group
them into larger units, such as years, quarters, or months. This adds flexibility to the pivot
table, and enables you to do things like comparing the results from one year to another, or
creating a running total by quarter.
You can also group numeric fields, when you add them to the Row Labels or Column
Labels area of the pivot table. By using this feature, you can group the numbers into larger
chunks, such as groups of 10 or 25. If comparing test scores, or results by age, you can look
at larger segments of the population, instead of individual scores or ages.
It’s also possible to manually group text items in the Row Labels and Column Labels
areas, so you can group cities into a region, or employees into teams, and summarize the
data for the group.
Most of the time, grouping goes smoothly, but you may hit snags, or see error messages
when you try to group the data in your pivot table. This chapter addresses those problems,
and provides solutions or workarounds for the issues you might encounter.
This chapter also covers problems that may arise when summarizing pivot table results
in subtotals and grand totals, and when summarizing fields in the Values area.
Except where noted, the problems in this chapter are based on the Stores.xlsx sample
workbook.
5.1. Grouping: Error Message When Grouping Dates
Problem
You created a pivot table with Category in the Column Labels area, Quantity in the Values area,
and OrderDate in the Row Labels area. The sales manager would like the dates grouped by
month, instead of seeing quantities for the individual dates.
This seemed like a simple request, but you get an error message, “Cannot group that
selection” (see Figure 5-1), when you right-click a date cell, and then click Group. This prob-
lem is based on the GroupError.xlsx sample workbook.
101
CHAPTER 5
Figure 5-1. This is the error message you see when items in a field can’t be grouped.
Solution
This error occurs if there are cells that contain text, instead of dates, in the source data’s
OrderDate field. For example, you may have entered text, such as N/A, if a date was not avail-
able when the data was being entered. To correct the problem, you can do the following:
1. If any of the rows contain text, such as N/A, delete the text, or replace it with a date.
■
Caution
A blank cell does not cause problems with grouping, but use the Delete key to remove the text.
Don’t type a space character.
2. Refresh the pivot table, and try to group the items in the date field.
3. If you’re still unable to group the dates, remove the date field from the pivot table lay-
out, refresh the pivot table, and then add the date field to the pivot table again.
■
Tip
In the PivotTable Options dialog box, on the Data tab, if Number of Items to Retain Per Field is set to
None, you should be able to group the date field without following Step 3.
5.2. Grouping: Error Message When Grouping Numbers
Problem
The logistics manager has asked for a report on the quantities per order. You created a report
with Quantity in the Row Labels area, Category in the Column Labels area, and OrderDate in
the Values area, as Count of OrderDate. To simplify the report, you would like to show the
quantities in groups of ten, such as 1–10, and 11–20, and show the number of orders in each
grouping.
However, you get an error message that says, “Cannot group that selection,” when you try
to group the numbers. You checked the source data, and no text entries are in the Quantity
field. This problem is based on the GroupErrorNum.xlsx sample workbook.
CHAPTER 5
■
GROUPING AND TOTALING PIVOT TABLE DATA102
Solution
Sometimes, entries that look like numbers are not recognized as real numbers by Excel. The
numbers may have been copied or imported from another program, and they are text values
instead of real numbers.
A quick way to test if the numbers are being recognized is to select two or more cells that
contain numbers. Then, look in the status bar, at the bottom of the Excel window, to see if the
numbers show a Sum (see Figure 5-2). If only the Count is displayed in the status bar, the
numbers are stored as text.
Figure 5-2. The sum of selected cells shows in the status bar.
To correct the problem, you can do the following:
1. In the source data, convert the text to numbers, using one of the techniques described
in the following “How It Works” section.
2. After converting the text to numbers, refresh the pivot table, and then try to group the
numbers in the pivot table.
3. If you’re still unable to group the numbers, remove the number field from the pivot
table layout, refresh the pivot table, and then add the number field to the pivot table
again.
■
Tip
In the PivotTable Options dialog box, on the Data tab, if Number of Items to Retain Per Field is set to
None, you should be able to group the numbers without following Step 3.
How It Works
You can convert text “numbers” to real numbers in several ways. For example, you can use the
Paste Special command.
1. Select a blank cell in the workbook, and then copy it.
2. In the source data, select the cells that contain the text “numbers.”
CHAPTER 5
■
GROUPING AND TOTALING PIVOT TABLE DATA 103
3. On the Ribbon, click the Home tab, and in the Clipboard group, click the lower section
of the Paste command, and then click Paste Special (see Figure 5-3).
Figure 5-3. Paste Special command on the Ribbon
4. In the Paste Special dialog box, in the Operation section, select Add, and then click OK.
Another method for converting text numbers to real numbers is to use the Text to
Columns feature.
1. Select the cells that contain the numbers you want to convert.
2. On the Ribbon’s Data tab, in the Data Tools group, click Text to Columns.
3. In the Convert Text to Columns Wizard, in Step 1, click Finish.
5.3. Grouping the Items in a Report Filter
Problem
You added the OrderDate field to the Report Filter area, and a long list of dates is in the drop-
down list. The sales manager frequently asks for a report for a specific month, so you would
like to group the dates by month, to make it easier to filter the report.
However, when you select the cell that contains the OrderDate drop-down list, the Group
Field command on the Ribbon’s Options tab isn’t available. This problem is based on the
Stores.xlsx sample workbook.
Workaround
You can’t group the items in a field located in the Report Filter area. Temporarily move the
OrderDate field to the Row Labels or Column Labels area and group the dates, and then move
the OrderDate field back to the Report Filter area.
CHAPTER 5
■
GROUPING AND TOTALING PIVOT TABLE DATA104
5.4. Grouping: Error Message About Calculated Items
Problem
You’re trying to group the dates in the OrderDate field, and you’re getting an error message
that says, “You cannot add a calculated item to a grouped field” (see Figure 5-4). The Order-
Date field doesn’t have any calculated items.
The only field with a calculated item is the Category field, and it’s not in the pivot table
layout. This problem is based on the GroupErrorCalc.xlsx sample workbook.
Figure 5-4. Error message about calculated items
Workaround
Although the OrderDate field has no calculated items, another field in the pivot table has a
calculated item, and that’s preventing the grouping. Even though the other field is not visible
in the pivot table, it can still prevent the grouping.
■
Tip
When troubleshooting pivot table problems, it may help if you know what formulas are in the pivot
table. To create a list of calculated items and calculated fields, select a cell in the pivot table, and on the
Ribbon’s Options tab, click Formulas, and then click List Formulas.
You can use one of the following workarounds:
• Delete the calculated item in the Category field, and then group the dates in the Order-
Date field.
• Add a new field in the source data, with a formula to do the calculation, instead of using
a calculated item in the pivot table. Then, add the new field to the pivot table, and
delete the calculated item.
• Add a new field with formulas in the source data to create date groups. For example,
add a new column with the heading “YearMonth” and use the following formula to
show the year and month, for a date in cell A2:
=TEXT(A2,"yyyy-mm")
Then, refresh the pivot table, and add the YearMonth field to the Row Labels area,
instead of using the OrderDate field.
CHAPTER 5
■
GROUPING AND TOTALING PIVOT TABLE DATA 105
5.5. Grouping Text Items
Problem
Three new stores opened last year and the sales manager asked you for a report that compares
quantities sold in the new stores to sales in the older stores. You added the Store field to the
Row Labels area of your pivot table, and you’d like to divide the stores into Old and New groups.
The three lowest numbers are the older stores, and the three highest are the newer stores.
However, when you select a label in the Store field, the Group Field command on the
Ribbon’s Options tab isn’t available, so you aren’t sure how to create the groups. This problem
is based on the Stores.xlsx sample workbook.
Solution
The Group Field command is only available for date and number fields in the Row Labels or
Column Labels area of the pivot table. Because the store numbers are entered as text, and
that’s how you want them to remain, you can use the following method to group the stores.
1. Manually select the stores you want in the first group. To select nonadjacent stores,
hold the Ctrl key, and then click the store numbers. In the sample file, select stores
3000, 3036, and 3062.
2. On the Ribbon’s Options tab, click Group Selection (see Figure 5-5).
Figure 5-5. Group Selection command
This creates a group named Group1, with the selected stores listed under that heading
(see Figure 5-6). For each of the remaining stores, a heading is created, with its store
number.
Figure 5-6. Group1 created in the Row Labels area
3. Select the Group1 heading, and then type a name for the group, such as Old.
4. Select the remaining stores, and click the Group Selection command to group them.
Name the second group as New.
CHAPTER 5
■
GROUPING AND TOTALING PIVOT TABLE DATA106
■
Tip
To select the remaining stores, drag down through the list of store numbers in the Row Labels area.
You can include the store number headings that were created.
As an alternative to grouping the stores in the pivot table, you could add a StoreType
field to the source data, and then enter Old or New for each record. Add the StoreType field
as the first field in the Row Labels area and the stores will appear under the correct Store-
Type heading.
5.6. Grouping Dates by Month
Problem
Your pivot table is based on two years of sales data. When you group the order dates in your
pivot table by month, the January data from both years is lumped together. You’d like to keep
the data from different years separated, so you can compare the monthly data between years.
This problem is based on the GroupMonth.xlsx sample workbook.
Solution
When you group the dates, select both Year and Month in the Group By list. With this type of
grouping, data from each year is grouped, and within each year, the data for each month is
grouped.
A Years field is automatically added to the PivotTable Field List, and you can move it to a
different area of the pivot table. For example, you could move Years to the Report Filter area,
and leave the OrderDate field, showing Months, in the Row Labels area.
5.7. Grouping Dates Using the Starting Date
Problem
You want to group the order dates into four-week periods that coincide with your sales calen-
dar. You successfully group the dates, but the date ranges are a couple of days off, starting
midweek instead of on a Monday. This problem is based on the GroupStart.xlsx sample
workbook.
Solution
When you group the dates, select to group by days, and set the number of days to 28. As a
starting date, Excel automatically selects the first date in your source data, but you can enter a
different date, to get the starting date you need.
For example, if the default starting date is Thursday, January 3, 2008, you could enter
December 31, 2007 as the starting date for your grouping (see Figure 5-7). This forces all the
groupings to start on a Monday, and it matches the company’s sales periods.
CHAPTER 5
■
GROUPING AND TOTALING PIVOT TABLE DATA 107
Figure 5-7. Changing the starting date
5.8. Grouping Dates by Fiscal Quarter
Problem
You added the OrderDate field to the Row Labels area of your pivot table, and you were able to
group the dates by year and quarter. However, you want to group the dates by your company’s
fiscal quarter, which starts in July, instead of using the calendar quarter available in the
Grouping dialog box. This problem is based on the GroupQtr.xlsx sample workbook.
Workaround
There’s no built-in option to group by fiscal quarter. In the source data, you can add a col-
umn with a formula that calculates the fiscal quarter, and then add that field to the pivot
table. For example, if your fiscal year starts in July, use the following formula to calculate the
fiscal quarter:
=CHOOSE(MONTH(A2),3,3,3,4,4,4,1,1,1,2,2,2)
In the Choose formula, the first argument, Month(A2), returns the month of the date in cell A2.
It uses that number to select the appropriate fiscal quarter number from the numbers that fol-
low. For example, if the month is April, the month number is 4. In the Choose formula, the
fourth number is 4, so that is the fiscal quarter in which April falls.
In another column, you can also calculate the fiscal year. For example, if fiscal year 2009
starts in July 2008:
=YEAR(A2)+(MONTH(A2)>=7)
Refresh the pivot table, and then ungroup and remove the OrderDate field. Add the fiscal year
and fiscal quarter fields to the Row Labels area.
5.9. Grouping Dates by Week
Problem
You added the OrderDate field to the Row Labels area, and you want to group dates by week,
but that option isn’t available in the Grouping dialog box. You could create a formula in the
source data, to calculate the week number, but you’d prefer to group the dates in the pivot
table. This problem is based on the GroupWeek.xlsx sample workbook.
CHAPTER 5
■
GROUPING AND TOTALING PIVOT TABLE DATA108