Problem
The sales manager sent you a workbook with sales data, and she asked you to create a pivot table from the data. You added the Product field to the Row Labels area, the District field to the Report Filter area, and Units and TotalSales to the Values area.
When you added the Units field to the Values area, it automatically used the Sum func- tion, but when you added the TotalSales field to the Values area, it used the Count function.
You’re not sure why different functions were used for two fields that both contain numbers.
This problem is based on the OfficeSales.xlsxsample file.
Solution
Perhaps blank cells were in the source data for the TotalSales field. If you add a number field to the Values area, the default summary function is Sum. However, if blank cells, or nonnumeric data, such as text or errors, are in the field, the Count function is used as a default.
■ Note You cannot change the default summary function in a pivot table. Either Sum or Count will be used, depending on the field’s contents.
After a field has been added to the Values area, you can change its summary function, unless the field is a calculated field, or the pivot table is based on an OLAP data source:
1. Right-click a cell in the field you want to change, and click Summarize Data By.
2. Click one of the functions in the menu (see Figure 3-1).
41
Figure 3-1.Select a summary function.
3. If the function you want is not visible, click More Options. Click a function in the Sum- marize Value Field By list, and then click OK (see Figure 3-2).
Figure 3-2.The Value Field Settings dialog box with a list of summary functions
■ Tip You can add two copies of a field to the pivot table’s Values area, and use a different summary func- tion for each copy. For example, show the Sum of Units and the Average of Units.
How It Works
When you add a field to the pivot table’s Values area, a list of 11 functions (listed as follows) is available to summarize the data. Only these functions are available when summarizing the pivot table data; other functions, such as Median, Mode, and Percentile, can be calculated from the source data, outside the pivot table.
The summary functions in a pivot table are similar to the worksheet functions with the same names, with a few differences as noted in the descriptions that follow.
Sum
Sumis the default summary function for numerical fields added to the pivot table’s Values area, and it totals all the underlying values in the Values area. The result is the same as using the SUM function on the worksheet to total the values.
Count
Countis the default summary function when fields with nonnumeric or blank cells are added to the Values area. Like the COUNTA worksheet function, the pivot table Count function counts text, numbers, and errors. Blank cells are not counted.
Average
The Average function totals all the underlying values in the Values area, and it divides by the number of values. The result is the same as using the AVERAGE function on the worksheet to calculate the average (mean) of the values.
Max
TheMaxsummary function shows the maximum value from the underlying values in the Values area. The result is the same as using the MAX function on the worksheet to calculate the maximum of the values.
Min
The Minsummary function shows the minimum value from the underlying values in the Values area. The result is the same as using the MIN function on the worksheet to calculate the minimum of the values.
Product
The Product summary function shows the result of multiplying all the underlying values in the Values area. The result is the same as using the PRODUCT function on the worksheet to calculate the product of the values. The results of this function may be very large numbers and default to a Scientific number format. Excel only stores and calculates with 15 significant digits of precision, so after the 15th character you’ll only see zeros.
Count Numbers
The Count Numberssummary function counts all the underlying numbers in the Values area.
The result is the same as using the COUNT function on the worksheet. Blank cells, errors, and text are not counted.
StDev
Like the STDEV worksheet function, the StDev summary function calculates the standard deviation for the underlying data in the Values area.
If the count of items is one, a #DIV/0! error is displayed, because one is subtracted from the count when calculating the standard deviation.
There may be differences between the worksheet results and the pivot table results, because the worksheet function was improved in Excel 2003, but the pivot table function was not changed. For more information, see the Microsoft Knowledge Base article “Description of Improvements in the Statistical Functions in Excel 2003 and in Excel 2004 for Mac,” at http://
support.microsoft.com/default.aspx?kbid=828888.
StDevp
Like the STDEVP worksheet function, theStDevpsummary function calculates the standard deviation for the entire population for the underlying data in the Values area. In Excel 2003, improvements were made to several statistical functions, including STDEV and STDEVP. See the previous “StDev” section for more information.
Var
Like the VAR worksheet function, the Var summary function calculates the variance for the underlying data in the Values area, and is the square of the standard deviation.
If the count of items is one, a #DIV/0! error is displayed, because one is subtracted from the count when calculating the standard deviation.
In Excel 2003, improvements were made to several statistical functions, including VAR and VARP. The Var and Varp summary functions have been improved when used in the interior of the PivotTable report, but not for grand totals for rows or columns. For more information, see the Microsoft Knowledge Base article “Excel Statistical Functions: VAR and VARP Improve- ments and Pivot Tables,” at http://support.microsoft.com/default.aspx?kbid=829250.
Varp
The Varp summary function calculates the variance for the entire population for the under- lying data in the Values area. In Excel 2003, improvements were made to several statistical functions, including VAR and VARP. See the previous “Var” section for more information.
Errors in the Source Data
The Count and Count Numbers functions handle errors as outlined earlier. For other sum- mary functions, if errors are in the source data field, the first error encountered is displayed in the pivot table, and the total is not calculated. If subtotals, or row and column totals, are dis- played, affected totals and subtotals display the error.
For example, the source data shown in Figure 3-3, from the sample file
OfficeSalesError.xlsx, has two errors for West Binder data—a #REF! error and an #N/A error.
Figure 3-3.Errors in the sample source data
The first error, #REF!, appears in the pivot table, when West Binder TotalSales are summed (see Figure 3-4). If the dates in the source Excel table were sorted in descending order, the
#N/A error would be listed first, and would appear in the pivot table.
Figure 3-4.The first error in the source Excel table appears in the pivot table.