Pivot Tables
Pivot Tables
Insert a Pivot Table | Drag fields | Sort | Filter | Change Summary Calculation | Two-dimensional Pivot
Table
Pivot tables are one of Excel's most powerful features. A pivot table allows you to extract the significance
from a large, detailed data set.
Our data set consists of 213 records and 6 fields. Order ID, Product, Category, Amount, Date and
Country.
The following dialog box appears. Excel automatically selects the data for you. The default location for a
new pivot table is New Worksheet.
3. Click OK.
Drag fields
The PivotTable Fields pane appears. To get the total amount exported of each product, drag the following
fields to the different areas.
1. Product field to the Rows area.
Sort
To get Banana at the top of the list, sort the pivot table.
Result.
Filter
Because we added the Country field to the Filters area, we can filter this pivot table by Country. For
example, which products do we export the most to France?
3. Choose the type of calculation you want to use. For example, click Count.
4. Click OK.
Group Products
The Product field contains 7 items. Apple, Banana, Beans, Broccoli, Carrots, Mango and Orange.
3. In the pivot table, select Beans, Broccoli, Carrots, Mango and Orange.
Conclusion: Apple and Banana (Group1) have a higher total than all the other products (Group2)
together.
Group Dates
To create the pivot table below, instead of the Product field, add the Date field to the Rows area. The
Date field contains many items. 1/6/2016, 1/7/2016, 1/8/2016, 1/10/2016, 1/11/2016, etc.
Result:
Pivot table:
3. Next, click any cell inside the Sum of Amount2 column.
Result:
The pivot table shows all the 'Broccoli' orders to the United Kingdom.
Frequency Distribution
Did you know that you can use pivot tables to easily create a frequency distribution in Excel? You can also
use the Analysis Toolpak to create a histogram.
Remember, our data set consists of 213 records and 6 fields. Order ID, Product, Category, Amount, Date
and Country.
First, insert a pivot table. Next, drag the following fields to the different areas.
1. Amount field to the Rows area.
9. Click OK.
Result:
Result:
Pivot Chart
Insert Pivot Chart | Filter Pivot Chart | Change Pivot Chart Type
A pivot chart is the visual representation of a pivot table in Excel. Pivot charts and pivot tables are
connected with each other.
Below you can find a two-dimensional pivot table. Go back to Pivot Tables to learn how to create this
pivot table.
3. Click OK.
Below you can find the pivot chart. This pivot chart will amaze and impress your boss.
Note: any changes you make to the pivot chart are immediately reflected in the pivot table and vice versa.
1. Use the standard filters (triangles next to Product and Country). For example, use the Country filter to
only show the total amount of each product exported to the United States.
2. On the Design tab, in the Type group, click Change Chart Type.
3. Choose Pie.
4. Click OK.
Result:
Note: pie charts always use one data series (in this case, Beans). To get a pivot chart of a country, swap
the data over the axis. First, select the chart. Next, on the Design tab, in the Data group, click Switch
Row/Column.
Slicers
You can insert slicers in Excel to quickly and easily filter pivot tables. However, using the report filter gives the
exact same result.
Below you can find a two-dimensional pivot table. Go back to Pivot Tables to learn how to create this pivot table.
To insert a slicer, execute the following steps.
4. For example, click Fruit to only show the fruit exported to each country.
Note: the report filter (cell B1) changes to Fruit. Hold down CTRL to include fruit and vegetables.
2. On the Analyze tab, in the Data group, click Change Data Source.
Tip: change your data set to a table before you insert a pivot table. This way your data source will be updated
automatically when you add or delete rows/columns. This can save time. You still have to refresh though.
Calculated Field/Item
Calculated Field | Calculated Item
This example teaches you how to insert a calculated field or calculated item in a pivot table.
Below you can find a pivot table. Go back to Pivot Tables to learn how to create this pivot table.
Calculated Field
A calculated field uses the values from another field. To insert a calculated field, execute the following steps.
2. On the Analyze tab, in the Calculations group, click Fields, Items & Sets.
6. Click Add.
Note: use the Insert Field button to quickly insert fields when you type a formula. To delete a calculated field, select
the field and click Delete (under Add).
7. Click OK.
Result:
Calculated Item
A calculated item uses the values from other items. To insert a calculated item, execute the following steps.
2. On the Analyze tab, in the Calculations group, click Fields, Items & Sets.
3. Click Calculated Item.
6. Click Add.
Note: use the Insert Item button to quickly insert items when you type a formula. To delete a calculated item, select
the item and click Delete (under Add).
7. Repeat steps 4 to 6 for North America (Canada and United States) and Europe (France, Germany and United
Kingdom) with a 4% and 5% tax rate respectively.
8. Click OK.
Result:
GetPivotData
To quickly enter a GETPIVOTDATA function in Excel, type an equal sign (=) and click a cell in a pivot
table. The GETPIVOTDATA function can be quite useful.
1. First, select cell B14 below and type =D7 (without clicking cell D7 in the pivot table) to reference the
amount of beans exported to France.
2. Use the filter to only show the amounts of vegetables exported to each country.
Note: cell B14 now references the amount of carrots exported to France, not the amount of beans.
GETPIVOTDATA to the rescue!
3. Remove the filter. Select cell B14 again, type an equal sign (=) and click cell D7 in the pivot table.
4. Again, use the filter to only show the amounts of vegetables exported to each country.
Note: the GETPIVOTDATA function correctly returns the amount of beans exported to France.
5. The GETPIVOTDATA function can only return data that is visible. For example, use the filter to only
show the amounts of fruit exported to each country.
Note: the GETPIVOTDATA function returns a #REF! error because the value 680 (beans to France) is not
visible.
6. The dynamic GETPIVOTDATA function below returns the amount of mango exported to Canada.
Note: this GETPIVOTDATA function has 6 arguments (data field, a reference to any cell inside the pivot
table and 2 field/item pairs). Create a drop-down list in cell B14 and cell B15 to quickly select the first and
second item (see downloadable Excel file).
7. The GETPIVOTDATA function below has 4 arguments (data field, a reference to any cell inside the
pivot table and 1 field/item pair) and returns the total amount exported to the USA.
8. If the total amount exported to the USA changes (for example, by using a filter), the value returned by
the GETPIVOTDATA function also changes.
If you don't want Excel to automatically insert a GETPIVOTDATA function, you can turn off this feature.
9. Click any cell inside the pivot table.
10. On the Analyze tab, in the PivotTable group, click the drop-down arrow next to Options and uncheck
Generate GetPivotData.
2,5 folder