In previous chapters, you used a pivot table to summarize insurance policy data and reported on the grand total of insured value by region and by building construction type. In most of the reports, you showed a total sum, and in one report you changed the report so it showed a total count of the policies sold. In this chapter, you'll use different data to create a pivot table, and you'll explore other ways of summarizing the data. You'll work with the grand totals and subtotals in the pivot table and learn how to group the data for a range of numbers or dates.
To follow the examples in this chapter, download and open the sample file named WorkOrders_01.xlsx
, available at www.apress.com
. In this workbook, you'll find data about your company's service call work orders, including the costs, labor hours, payment type, whether parts or labor are covered under warranty, and other dates. Figure 4-1 shows a sample of the data.
Figure 4-1. Service call work orders data
You'll use a pivot table to summarize the work order data to see the following:
Note In the sample file, an Excel table named WorkOrders has been created from the work order data. If you are using your own data to work through the instructions in this chapter, you should create an Excel table from your data and then name the Excel table.
Your first task is to create a report on the average hours that each technician spends on the different types of service calls. This will help your service coordinator schedule the service calls, because you'll know how long each type of job normally takes. To get started, you'll check the source data to see which fields contain the data that you need for your report and then create a pivot table with those fields:
This report gives you an overview of the type of service that each technician is doing, with a sum of labor hours, as shown in Figure 4-2.
Figure 4-2. Sum of labor hours per service type
Note In this chapter's figures, some column widths have been manually adjusted.
Because the LbrHrs column in the source data consists of numbers only, it was automatically summarized as Sum of LbrHrs when you added it to the pivot table. If the LbrHrs field had contained cells with text or blank cells, it might have been summarized as Count of LbrHrs.
You'll make a change to the LbrHrs summary function to show the average time that each technician spends on each type of service:
Figure 4-3. Average labor hours per technician for each service type
Your report now shows the average hours per technician for each service call type. However, because the number of decimal places vary within the pivot table columns, it's hard to visually compare the results. You'll format the numbers so they are consistent, and the summary will be easier for you and other readers to understand at a glance:
Figure 4-4. Number Format command on the context menu
For this data, two decimal places will be sufficient, because 0.01 hour is just 36 seconds, and the service coordinator doesn't require anything beyond that level of precision. In other situations, you may require more decimal places.
With the values all showing the same number of decimal places, it's much easier to compare the data and to see that installations have the highest average time (see Figure 4-5). Thanks to your report, the service coordinator will be able to schedule enough time for those jobs.
Figure 4-5. Consistent number formatting makes comparisons easier.
When you add date and number fields to the Values area, Sum is the default summary function, and when you add text fields to the Values area, Count is the default summary function. Although these are the most commonly used functions, other functions may be required for some of your pivot table analysis. Including Sum and Count, you can use 11 summary functions for the value fields; Table 4-1 shows a brief overview of these functions.
Function | Description | Similar Worksheet Function |
Sum | Totals the source data | SUM |
Count | Counts numbers, text. and errors in the source data | COUNTA |
Average | Totals the source data and divides by the number of values | AVERAGE |
Max | Shows the highest value from the source data | MAX |
Min | Shows the lowest value from the source data | MIN |
Product | Multiplies all the source data and may result in a very large number | PRODUCT |
Count Numbers | Counts the numbers in the source data | COUNT |
StdDev | Shows the standard deviation for a sample of the source data | STDDEV |
StdDevp | Shows the standard deviation for the entire population for the source data | STDDEVP |
Var | Shows the variance for a sample of the source data | VAR |
Varp | Shows the variance for the entire population for the source data | VARP |
The first six summary functions—Sum, Count, Average, Max, and Product—are available on the context menu when you right-click a value cell in the pivot table. To give the service coordinator a better idea of the range of times required for a job, you'll create two more reports, using the Min (minimum) and Max (maximum) functions:
You can apply the remaining summary functions by using the More Options command as described next. You'll create one more report for the service coordinator by using the StdDevp (standard deviation) function.
This compares the labor hours for each job to the average labor hours for that technician on that type of job. A lower number means that there is less variance in the labor hours. Because all the deliveries are a fixed time of .25 hours, the standard deviation is zero for all the technicians. Assessments ranged from .25 hours to 2 hours, so the standard deviation for all the technicians is low. For installation jobs, the standard deviation is much higher for most of the technicians, and this indicates there is a wide range of times for repair jobs. For example, Michner's labor hours ranged from 1 to 19.5 hours, resulting in a standard deviation of 3.79. The StdDevp function was used instead of StDev because the source data for the pivot table is all the service call data (the entire population) for the company for the past two years. If you had only a sample of the service call data, you could use the StDev function.
The pivot table now shows the average time per service type for each technician.
Now that you have calculated the average times, the service coordinator has asked you to show a count of jobs where the labor was done under warranty. You check the source data and see a column with the heading WtyLbr. WtyLbr is a text field that contains Yes if the labor is covered by warranty.
Currently, the pivot table shows the Average of LbrHrs values, and you'll add the Count of WtyLbr values to show how many service calls were performed under a labor warranty:
Figure 4-6. Two value fields in the pivot table
With the two value fields now in the pivot table, you can see that Assessments had the greatest number of jobs done under a labor warranty and that Michner is the technician with the highest average labor hours per assessment call.
When a field is added to the Values area of the pivot table, its heading cells show its summary function and its field name. For example, in your pivot table the value fields have the rather long headings of Average of LbrHrs and Count of WtyLbr. To make the headings easier to read, you can shorten them:
Figure 4-7. Value Field Settings option in the PivotTable Field List pane
A quicker way to change the value field heading is to make the change directly in a pivot table cell:
Tip The custom name cannot be the same as the field name in the source data. You can add a space in the text, or at the end of the text, to make the custom name slightly different from the field name.
In the pivot table and in the Values area of the PivotTable Field List pane, the value fields now show the custom names you entered. As a result, the columns can be narrower, and the headings are easier to read.
Now that you've finished your reports for the service coordinator, the accountant wants a report on the total service fees and average fee for each type of service call. You'll change the pivot table fields to focus on the fees collected instead of on the hours.
Before you make any changes to the pivot table, you check the source data to see which fields you'll use to calculate the fees. The TotalFee column includes the labor fees and parts fees for each work order and shows the total amount collected on the work order.
In the labor hour reports, you used two different fields in the Values area. For this report you'll add two copies of the TotalFee field to the Values area and use a different summary function in each copy. You'll clear the pivot table to get a fresh start, and then you'll add the fields you need for the accountant's report:
Note The currency symbol in your pivot table will depend on the regional settings in your computer.
The pivot table now shows the total charged for each service type and the average amount charged for each service type (see Figure 4-8). Replacements have the highest total fees collected, and installations have the highest average fee.
Figure 4-8. Two copies of the same value field in the pivot table
Changing the Order of the Value Fields
Once you have multiple value fields in the pivot table, you may want to rearrange them. You'll move the Avg WO field so it is to the left of the Total WO field in the pivot table layout:
Tip Don't drag the field too high, or it will be removed from the pivot table layout. If the pointer has a circle with a bar through it, that indicates the field cannot be dropped in its current location.
Figure 4-9. Drag a value to a new position in the PivotTable Field List pane.
In the pivot table on the worksheet, the value fields switch places, and the Avg WO column is to the left of the Total WO column. Another way to change the value field order is to make the change directly in the pivot table.
Figure 4-10. Drag a value to a new position in the pivot table.
In the PivotTable Field List pane, the value fields switch places, and Avg WO is below Total WO.
Changing the Position of the Value Fields
When you add multiple value fields to a pivot table, their headings appear, by default, in the column area. If you prefer, you can move the headings to the row area, where the value fields will be listed vertically instead of horizontally.
In the PivotTable Field List pane, Excel automatically adds a special field button when multiple value fields are in the layout. You'll use that button to relocate the value fields.
Figure 4-11. Value field labels in the PivotTable Field List pane
In the pivot table, the value field labels are listed under each service type. To see the summary differently, you could move the Σ Values field in the PivotTable Field List pane so it's above the Service field in the Row Labels area. With that layout, the services would be listed under each value field heading.
On some service calls, two technicians are required instead of just one. The service manager wants a report on the labor costs for one-technician and two-technician jobs for each type of service call. You check the source data and see a column with the heading Techs. The number in that column indicates whether one or two technicians were required. You can use the column with the heading LbrCost to show the total labor costs for each work order.
First you'll clear the pivot table layout, and then you'll add different fields so you can analyze the labor cost for each type of service call:
The pivot table now shows the total labor cost for each service type, and there is a grand total at the bottom of the pivot table that totals the columns of labor costs and labor hours for all services (see Figure 4-12). These are the grand totals for columns.
Figure 4-12. Grand totals for columns
Because there are no label fields in the Column Labels area, the pivot table has no grand totals for rows. There is nothing in the pivot table that should be totaled across the row—labor cost and labor hours are different fields and shouldn't be totaled.
The service manager wants the summary by one- and two-technician calls, so you'll add the Tech field to the Column Labels area:
Now that there is a field in the Column Labels area, there is a grand total for rows at the right of the pivot table, which shows the total labor cost for each service type (see Figure 4-13). There is still a grand total for columns at the bottom of the pivot table, which totals the labor costs and shows the total cost for one-technician calls, the total cost for two-technician calls, and the total for all calls.
Figure 4-13. Grand totals for rows and grand totals for columns
When you add fields to the Row Labels or Column Labels area, Excel automatically adds the grand totals to the pivot table layout. In some cases, you may not want either of the grand totals displayed. You'll hide the row grand total at the right of the pivot table. This will reduce the number of columns in the pivot table and will help focus the reader's attention on the comparison between one-technician and two-technician calls.
Figure 4-14. The pivot table Options command
Figure 4-15. Set the grand totals options
The grand totals for rows, at the right of the pivot table, have been removed, and the grand totals for columns are still visible. The one-technician and two-technician calls can be compared, without the distraction of the grand totals for rows.
When you want to see the grand totals for rows again, you can use a command on the Ribbon to turn them on. You'll show the grand totals for rows in your pivot table again:
The grand totals for rows reappear in the pivot table.
The accountant likes the labor cost report you produced and has asked to see the labor costs broken down by rush and nonrush calls for each service type. In the source data, you find a column with the heading Rush. If a rush job was requested, a Yes is entered in that column. You'll add the Rush field to the pivot table layout.
Currently your pivot table has one field in the Row Labels area and one field in the Column Labels area. When you add a second field to the Row Labels area, subtotals will be created.
Excels adds the Rush field to the Row Labels area in the pivot table, and each label in the Service field shows a subtotal of the Rush labels below it (see Figure 4-16). The rows with a Yes label are the rush calls, and the rows with a (blank) label are the nonrush calls.
Figure 4-16. Subtotals for Row Labels area
Excel will also add subtotals to the pivot table if you place more than one field in the Column Labels area. To see a more detailed breakdown of the labor costs, you'll add the LeadTech field to the pivot table layout. That will let you see, for one-technician and two-technician jobs, what each technician's total labor costs are.
The LeadTech field is added to the Column Labels area in the pivot table and subtotals the labor costs for one-technician and two-technician jobs (see Figure 4-17).
Figure 4-17. Subtotals for Column Labels area
When there are multiple fields in the Row Labels area or the Column Labels area, the last field in the list of fields is called an inner field (see Figure 4-18). All the fields above it in the list of fields are called outer fields. Only the outer fields automatically display subtotals. The inner field does not.
In Figure 4-18 the District field has been added to the Row Labels area.
Figure 4-18. Inner and outer fields in the PivotTable Field List pane
Because it is the last field in the list of Row Labels, District is the inner field and doesn't display subtotals. Rush, which was previously the inner field, becomes an outer field, and displays subtotals. Remove the District field, and the Rush is once again the inner field.
As you have seen, subtotals are automatically added when multiple fields are placed in the Row Labels area or Column Labels area of the pivot table. Although the subtotals can add useful information, you don't always want them in the pivot table. To simplify a pivot table layout, you may want to hide the subtotals for one or more of the pivot fields.
First you'll change the subtotal settings for all the fields in the pivot table, and later you'll adjust the settings for individual fields. Because the pivot table looks a bit crowded, with all the columns of labor costs, you'll turn off all the subtotals in the pivot table to see whether that improves the appearance.
Figure 4-19. Subtotals command on the Ribbon
The Service labels remain in the pivot table, but the labor costs have been removed from those rows. The columns with total labor costs for each lead technician have also been removed. The grand totals for rows and grand totals for columns remain in the pivot table.
It was easy to hide the subtotals for all the fields in the pivot table, but now suppose you'd like to show the subtotals for the Service field to see the total cost per service type. You'll change the subtotal setting for just that field:
The LeadTech subtotals remain hidden, but the subtotals for the Service field are now visible. The grand totals for rows and columns remain in the pivot table.
In a pivot table layout, subtotals for the Row fields can appear above or below the items that they subtotal. Currently, the Service field in your pivot table has its subtotals displayed above its items. You'll change one of the pivot table settings to display all the subtotals again and select a position in which to display the row subtotals:
Note Changing this setting will affect the position of the subtotals in all the row fields in the pivot table.
The subtotals for the Service field appear above the rush items. Because the Rush field is the last field in the Row Labels area, with no items below it, the Rush field is an inner field and does not display subtotals. The LeadTech field, in the Column Labels area, also shows subtotals again, but these come after the LeadTech items. Only the subtotals in the Row Labels area change position.
Next, you'll apply the remaining option for subtotals to display them below the items.
The outer row field, Service, displays a heading row with only a label at the top of the group and a subtotal row at the end of the group of items (see Figure 4-20). The Column Labels subtotals do not change.
Figure 4-20. Subtotals at bottom of group
When subtotals appear in the pivot table, they automatically use the Sum function to total the data in the group. You can change the function that is used to summarize the value fields just as you changed the summary function for a value field. You'll change the summary function for the Service subtotals to see a count instead of a sum.
Note If there are multiple value fields in the pivot table, the subtotal functions will be the same for all value fields. You can't apply different summary functions to the individual value fields in a pivot table.
The subtotals for the Service field now show the count of records for each service type, and the label for the subtotal has changed to end with Count, instead of Total. For example, the first service type is Assess, and its subtotal label has changed from Assess Total to Assess Count.
Note If you point to a custom subtotal value, the pivot table tool tip will show the name of the value field, not the summary function used in the subtotal. For example, if you point to cell B9, its tool tip title is Sum of LbrCost, not Count of LbrCost. The Row information in the tool tip is correct and shows Row: Assess Count.
Figure 4-21. Custom functions for subtotals
When subtotals are automatically created in the pivot table, there is only one subtotal row peritem. You can create additional subtotals to show other summary functions. Your pivot table currently shows the sum of labor cost in the Service field. You can add another subtotal to the field to show the highest labor cost.
Note If you include more than one subtotal for a field, the subtotals for that field are shown at the bottom of the group, even if you have selected Show All Subtotals at Top of Group.
The accountant's report on labor costs is now completed. The subtotals for the Service field show the sum of labor cost and the highest labor cost, while the label for each subtotal shows its summary function name (see Figure 4-22).
Figure 4-22. Multiple subtotals
Note Grand totals may be incorrect for subtotals if the function used is different from the function used in the value field. You may want to hide the grand totals when using subtotals with custom functions.
Up to this point, you've added fields to the Row Labels area and Column Labels area and then summarized the value fields by the labels that automatically appear. For example, when you added the Service field to the Row Labels area, the labels Assess, Deliver, Install, Repair, and Replace appeared in column A, and you summarized the labor hours or labor costs for each of those labels.
In a pivot table, you can group numbers, dates, or text to create new labels and summarize the data by these groups. For example, if your source data contains dates, you can group the dates by year to show annual totals. If the source data has numeric test scores, you can group the numbers into 1–50 and 51–100 and show a count of results in each range of scores.
The service manager wants to know how long customers are waiting for a service call. In the source data, you can see a column with the heading Wait. This is the number of days between the request date (ReqDate) and the day of the service call (WorkDate). To create a count, you'll use the WO field, which is the work order number. Every row has a work order number, so this will give you a reliable count.
You'll add the Wait field to the pivot table and organize the numbers into groups to create new labels. To start, you'll remove all the fields from the pivot table layout and then add different fields:
In the Row Labels area, you can see all the wait days listed, and in the next column is the count of work orders for each wait period. For example, 19 work orders had a 2-day wait, and 68 work orders had an 8-day wait (see Figure 4-23).
Figure 4-23. Wait days in the row labels
This level of detail may be required occasionally, but you could group the wait days, instead of listing each number individually. For example, you could list the days in groups of seven days, which would group the wait days into week lengths. This would give you a shorter list of items and would make it easier to spot which wait lengths are most common.
Figure 4-24. Group Field command
Note The Group Field command is available only if the currently selected field is a number or date field.
Figure 4-25. Grouping dialog box
Instead of individual wait days, the row labels now show number groups in seven-day intervals, such as 0–6 and 28–34 (see Figure 4-26).
Figure 4-26. Grouped numbers for Wait labels
You can send your report to the service manager, showing that most customers had a two-to three-week wait for service.
If your pivot table contains groups, you may want to remove them. You'll remove the grouping from the Wait field to show the individual numbers again.
The grouping is removed from the Wait field, and the individual Wait days are shown.
You can also group dates in a pivot table field to display a range of dates under one label. To determine the busiest times of the year, the service manager wants a report that shows a count of service calls for each month. The WorkDate field in your source data contains dates that span almost two years. Instead of summarizing the data by the individual work dates, you can group the dates by year and month. You'll remove the Wait field from the pivot table and move the WorkDate field into the Row Labels area:
In the Row Labels area, you can see all the work dates listed, and in the next column is the count of work orders for each day. However, the list is very long, and you want to see a summary for each month, instead of each day.
Figure 4-27. Grouping dialog box
Instead of individual dates, the row labels now show Years and Months so the service manager can see the number of work orders that were completed in each month.
In the PivotTable Field List pane, Excel adds a Years field to the end of the field list. You grouped by Years and Months so that the data for each year is summarized separately. If you selected only Months, the January data for both years would have been summarized together.
The service manager has assigned each technician to one of two teams, Team A and Team B. To see how the work orders have been split between the two teams, you'll create a report that counts the work orders for each group.
The Group Field command and Grouping dialog box work only for number and date fields. For text fields, you can select and group labels to display those items together. You'll remove the WorkDate field from the pivot table and move the LeadTech field into the Row Labels area:
In the Row Labels area, you can see all the technician names listed, and in the next column is the count of work orders for each technician. You'll group the lead technicians into the two teams—Burton, Ling, and Tremblay are in Team A, and Khan, Michner, and Mugford are in Team B.
This creates a new field named LeadTech2, which you can see in the PivotTable Field List pane, and a new set of labels in the pivot table. The group you created for the selected technicians is labeled Group1, and each of the remaining technicians has a separate label (see Figure 4-28).
Figure 4-28. Group selected labels
Next, you'll group the remaining technicians:
This creates another item, named Group2, in the LeadTech2 field.
When you create groups by using the Group Selection command, they are automatically given a numbered name, such as Group1. You can change these names, so they are more meaningful as headings in the pivot table. You'll change the group labels so they show the team names:
Figure 4-29. Group labels renamed
The pivot table now shows the lead technicians grouped into their teams. If you want to see the total for each team, you can turn on subtotals, above or below the group items. To see the team totals without the technician names, remove the check mark from LeadTech in the PivotTable Field List pane.
Note If you want to ungroup items that you grouped by selecting them, you will have to ungroup each group separately. Click a group's label cell, and then click the Ungroup command in the Ribbon. When the groups have all been ungrouped, the field's name will be removed from the PivotTable Field List pane.
You can save your file now as WorkOrders_02.xlsx
. That will leave the original file unchanged since its last save, and you can use the new file for your work in the next chapter.
In this chapter, you learned different ways to summarize the data in the pivot table. First, you changed the function that was used for a value field and tested the result of using different functions. You added multiple value fields and summarized the same value field using different functions.
Next, you hid and showed the grand totals for rows and columns, added subtotals to the outer fields in the pivot table, and positioned the subtotals above or below the items.
Finally, you grouped the items in the row fields to summarize by a range of numbers or a date range. For the text field, you manually selected and grouped the items.
I have now covered the basics of summarizing the pivot table data, and next you'll apply formatting to enhance the presentation of the data.
18.223.213.238