Mastering Pivot Tables in Excel
Description
The project starts with introducing Excel and pivot tables basics before gradually advancing to more complex functionalities. Learners will get both theoretical knowledge and hands-on experience through a series of practical exercises. The project will not only explain how to create a pivot table but also demonstrate its advantage in large scale data manipulation, and the accuracy and effectiveness it can offer.
Unit 1: Introduction to Excel and Pivot Tables Implementation Guide
Section I: Excel Setup
Assumes you have Microsoft Excel installed on your computer. If not, you will need to either purchase or subscribe to Office 365 to get the current version of Excel.
Unlock Excel: Open Excel by navigating to your applications or using the search function in your operating system to find and open Excel.
New Workbook: Once Excel is open, start with a new blank workbook from the default start-up screen.
Worksheet Navigation: Familiarize yourself with the layout. Worksheets tab at the bottom, rows numbered and columns lettered, the formula bar at the top displays content of the currently selected cell.
Input dummy data: For the purpose of this example, let's create dummy data with the columns "Month", "Sales Person", "Sales Unit", "Profits". Populate these with appropriate data values.
Months:[ "Jan", "Feb", "Mar", "Apr"]
Sales Person:["Jo", "Ann", "Mel", "Lee"]
Sales Units: [10, 15, 8, 13, 14, 9, 11, 10]
Profits: [500, 700, 600, 900, 650, 750, 560, 720]
3 spaces in each bracket represent a single instance in a row. Like: Jan, Jo, 10, 500 are all one row. Save and name your workbook as "Sales Data.xlsx".
Section II: Pivot Tables Setup
Pivot tables are incredibly useful tools for any data manipulation need in Excel. Here's how you create one using the prepared dummy data.
Select Data Source: You first have to select a range of data to analyze. Highlight all of your data, headers included.
Initiating Pivot Table: Navigate to the "Insert" tab in the Ribbon at the top of Excel, then select "PivotTable" in the Toolbar.
Create Pivot Table: You will get a pop-up box. Here, your previous selection for the data is already in the range. The next decision you have to make is where you want the PivotTable report to be placed. You can either place it in a new worksheet or an existing one. Choose what suits you best. Click OK.
Section III: Manipulating Pivot Tables
After you clicked OK, you should be seeing an empty PivotTable and Field List Page with your data headers.
- Configure fields: Simply drag 'Months' into Rows area, 'Sales Person' into Columns area, and both 'Sales Units' and 'Profits' into Values area.
By default, Excel summarizes your data by either summing or counting the items.
- Value field settings: If you wish, you can change how to calculate the values (from sum to count, average, min, max, etc.) by clicking the dropdown arrow next to the value you're interested in changing and select "Value Field Settings". Then select the calculation you wish to use.
You can now easily see your data organized and summarized in a neat table grouped by columns you specified!
This concludes this implementation of Unit 1: Introduction to Excel and Pivot Tables. You can now use this basic knowledge to dig deeper into the functionality of Excel Pivot Tables: adding additional field calculations, applying filters, and much more.
Unit 2: Steps to Creating a Basic Pivot Table
As a continuation from Unit 1 where we introduced Excel and Pivot Tables, in this unit, we'll be focusing on steps to create a basic pivot table.
Step 1: Select Data
The first step in creating pivot tables is selecting the data that you want to use.
1. Open the Excel spreadsheet that contains the data you want to analyze.
2. Click the cell at the top-left corner of the data group you want to evaluate.
3. Then, hold Shift and click the cell at the bottom-right corner of the data group.
Assuming that you have a data range comprising of 5 columns A
to E
, and 10 rows 1
to 10
, you would click on A1
, hold Shift, and then click on E10
.
Step 2: Open the Pivot Table Creator
Now to open the pivot tables creator:
1. Click on `Insert` in the toolbar at the top of the screen.
2. In the drop-down menu, click on `PivotTable`.
3. This further opens a pop-up box.
This will launch the Create PivotTable
dialog box in your spreadsheet, with your selected data already entered into the "Select a table or range" field.
Step 3: Create Pivot Table
In the pop-up box, I'm assuming that your range of data has headers, hence:
1. Make sure "Select a table or range" is chosen, and the range matches your selection.
2. Under "Choose where you want the PivotTable report to be placed", select "New Worksheet".
3. Click OK.
This creates a new worksheet with an empty pivot table and opens the "PivotTable Fields" tab on the right side of the screen.
Step 4: Choose Data For The Pivot Table
Now let's choose what data to include in the pivot table and how it should be displayed:
1. In the "PivotTable Fields" pane, under the list of fields, check the box for each field you want to include in your pivot table.
2. Drag and drop fields between "Filters", "Columns", "Rows", and "Values" areas depending on your requirement.
Let's say from your data, you are interested in the Sales
details for each Product
:
- You'll drag
Product
to theRows
field. - And
Sales
to theValues
field.
Now your basic pivot table, which shows the total Sales
for each Product
, is ready!
Remember, Excel doesn’t limit you to only rows and columns. You can also filter the data by any of the fields in the 'Filter' section.
This section gives the detailed steps for creating a basic pivot table. Advanced features or customizations, which allow for more complex data analyses, will be covered in subsequent units. Note that different versions of Excel might have slight differences in terms of menu labels and layouts.
Code For Google Sheets
For Google Sheets users, below is a step-by-step guide in Apps Script code equivalent to the process above. Using Apps Script allows you to create, access, and modify Google Sheets files.
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheets()[0];
var range = sheet.getRange("A1:E10");
var pivotTable = sheet.newPivotTable()
.setSourceData(range)
.addRowGroup("A") // replace "A" with the column header you want to group by.
.addValue("E", SpreadsheetApp.PivotTableSummarizeFunction.SUM) // Adds total sales. Replace "E" with the column header you want to summarize.
.setPosition(1, 1);
Please note that Google Sheets API must be enabled and properly set to use Apps Script.
Unit 3: Manipulating Data using Pivot Tables in Excel
In this unit, we will focus on various ways to manipulate data using Pivot tables. Let's consider you have a data set and you've already learnt from the previous units how to insert a basic Pivot table. Now, we will build on this knowledge and learn to manipulate data using Pivot Tables.
Task 1: Grouping Data
One of the most powerful features of Pivot Tables is their ability to group data. To implement this, follow the steps below:
Group by Dates:
- Click on any cell which contains date.
- Go to
Analyze Tab
->Group Selection
. - In the dialog box, select the appropriate time period (Months, Quarters, Years) and press OK.
- Your data will now be grouped by the chosen time period in the Pivot Table.
Group by other fields:
- Right-click on any data point you want to group.
- Click on
Group
. - In the Group By dialog box, specify the Start, End, and By values.
- Click OK. The selected values will be bucketed into the ranges you set.
Task 2: Creating Calculated Fields
Calculated fields are a way to create new data from data that already exists in your pivot table.
- Click anywhere in your Pivot Table.
- Go to the
PivotTable Analyze
tab and click onFields, Items & Sets
. - Select
Calculated Field
. - In the Name field, type a name for your calculated field.
- In the Formula field, create your formula. You can use Excel formulas normally, using fields from the Pivot Table by clicking the
Insert Field
button. - Click
Add
to insert the field into your Pivot Table.
Task 3: Using Slicers for easy filtering
Slicers provides a very interactive way to filter your data.
- Click on your Pivot Table and go to the
PivotTable Analyze
tab. - Click on
Insert Slicer
. - In the Insert Slicers dialog box, tick the checkbox of the field (one or multiple) you want to create a slicer for.
- Click OK. Slicers will be added to your worksheet.
- To filter data, simply select the items you want to be displayed from the slicer.
Task 4: Using Pivot Charts
Pivot Charts provide a graphical representation of your data, making it easier to analyze.
- Click on your Pivot Table and go to the
PivotTable Analyze
tab. - Click on the
PivotChart
command. - In the Insert Chart dialog box, choose the chart type and click OK.
- A new Pivot Chart will be inserted on your current worksheet.
These are few ways you can manipulate data using Pivot Tables in Excel. Each of these tasks can be applied in numerous ways depending on your analysis needs. Once you understand these, you can start combining them to perform more complex data analysis tasks.
Implementation of Unit 4: Advanced Pivot Table Features
Assuming that you have a basic understanding of pivot tables and you've created a simple pivot table, let's move onto some more advanced features. This section will cover:
- Grouping Fields
- Adding a Calculated Field
- Slicers
Data Set
Let's suppose we're working with a data set that contains information about the purchases made at a retail store:
| Order ID | Product | Category | Amount | Date | City |
Grouping Fields
Grouping helps in making better sense of data by categorizing it into different divisions. Excel allows users to group numeric as well as date fields.
Here is an example of how to group by Date (by month):
- First, create a simple pivot table with 'Date' in Rows area and 'Amount' in the Values area.
- Right-click on any date within the pivot table.
- Select 'Group'.
- In the Group by dialog box, select Months and click OK.
Excel will now display the total amount for each month, instead of each separate date.
Adding a Calculated Field
Calculated fields can be used when the data needed for analysis doesn’t exist in the raw data.
Here is how to add a Calculated Field:
- Select any cell in the pivot table.
- Go to Pivot Table Tools ➜ Analyze ➜ Calculations ➜ Fields, Items, & Sets ➜ Calculated Field.
- In the Name field, insert the name of the Calculated Field (in our case, we will use 'Average Order').
- In the Formula field, insert the formula for the Calculated Field. Our formula would be:
=Amount / COUNT('Order ID')
. - Click Add to insert the new field into the pivot table.
Our pivot table will now include an extra column, 'Average Order', that displays the average order value (Amount divided by the number of orders).
Slicers
Slicers are a visual way to filter the data in a pivot table. Unlike regular filters they provide a simple and intuitive way to filter data, providing buttons that you can click to filter the data.
Here is how to insert a Slicer:
- Click on any cell in the pivot table.
- Navigate to Pivot Table Tools ➜ Analyze ➜ Filter ➜ Insert Slicer.
- A dialog box will appear. Select the field(s) for which you want to create a Slicer. For example, 'City'.
- Click OK.
You will see a slicer box appear on the worksheet. You can click on a city (or multiple cities) and the Pivot Table will adjust to show only those cities you selected.
This sums up some of the advanced pivot table features.
Unit 5: Practical Application - Analysing Large Data Sets
In this section, we will deal with real-life scenarios of managing and analysing larger datasets which contains thousands of rows using Excel Pivot Tables.
Dataset
I will use an example dataset named SalesData.csv
containing 10000 rows and the following columns: ORDERID, QUANTITYORDERED, PRICEEACH, ORDERLINENUMBER, SALES, ORDERDATE, STATUS, PRODUCTLINE, MSRP
. This dataset is a typical example showing sales transactions data.
Loading the Data
For such big datasets, the recommended way to load the data into Excel is by using the Data Import
feature in Excel.
- Open Excel.
- Go to the
Data
tab. - In the
Get & Transform Data
section, clickGet Data
->From File
->From Text/CSV
. - Choose the
SalesData.csv
file from your system and click Import.
Creating Pivot Tables
Follow the steps from 'Unit 2: Steps to Creating a Basic Pivot Table' to create a pivot table from the loaded dataset.
Analysis
Now, let's do some analysis on the dataset following the steps from 'Unit 3: Manipulating Data using Pivot Tables' and 'Unit 4: Advanced Pivot Table Features'.
Analysis 1: Yearly Sales
- Drag and drop
ORDERDATE
into rows andSALES
into the values area. - By default, the
ORDERDATE
will be grouped by Year, Quarter and Month. Right click on the year row ->Group
-> deselectQuarter
andMonth
. - You will now see Total Sales for each Year.
Analysis 2: Yearly Sales by Product Line
- In addition to
ORDERDATE
andSALES
, drag and dropPRODUCTLINE
into the Rows area. - Reorder
PRODUCTLINE
to appear beforeORDERDATE
. - The Pivot Table would show you sales by product line, broken down by year.
Analysis 3: Top 5 Selling Products for Each Year.
- With
ORDERDATE
,PRODUCTLINE
andSALES
in the respective areas, dropORDERID
into the Values area. - Click the drop down arrow next to
Row Labels
->Value Filters
->Top 10
. - Change '10' to '5', click
OK
. - Now, the pivot table shows the Top 5 selling products for each year.
Conclusion
Excel Pivot Tables are resourceful tools for quickly analyzing large datasets without having to write complex formulae or subsets of data. These practical examples illustrate how you can extract actionable insights from the piles of raw data available.
Unit 6: Debugging and Solving Common Issues with Pivot Tables
Section 1: Understanding the Issue
1.1: Pivot Table Won't Update
If your pivot table is not updating properly, it could be because it's not connected to the correct data source or the data source has not been refreshed. This problem usually arises when the data is being updated externally or more rows/columns are added.
' Solution:
Sub RefreshPivotTable()
Sheets("YourSheetName").PivotTables("YourPivotTable").PivotCache.Refresh
End Sub
Make sure to replace "YourSheetName" and "YourPivotTable" with your specific sheet and pivot table names.
1.2: Incorrect or Incompatible Data Format
If your data fields are not appearing as expected (like dates appearing as integers), it's possible that Excel is reading the format incorrectly.
' Solution:
Sub ChangeFormat()
Sheets("YourSheetName").PivotTables("YourPivotTable").PivotFields("YourField").NumberFormat = "YourFormat"
End Sub
Replace "YourSheetName", "YourPivotTable", "YourField", and format the data accordingly. Examples of formats could be "General", "mm/dd/yyyy" (for dates), etc.
Section 2: Fixing Errors
2.1: Error - "PivotTable field name already exists"
This error pops up when two or more columns have the same header.
Solution:
The solution requires manual intervention to change or update the duplicate header fields. It's not available via VBA.
2.2: Missing pivot table data
This issue arises when there's Blanks/Null values in the data.
' Solution:
Sub HandleBlanks()
With Sheets("YourSheetName").PivotTables("YourPivotTable").PivotFields("YourField")
.PivotItems("(blank)").Visible = False
End With
End Sub
Replace "YourSheetName", "YourPivotTable" and "YourField" with your specific names.
Section 3: Performance Issues
3.1: Pivot Table Slowing Down Excel
A Pivot Table with a large data source might slow down Excel. One way to tackle this issue is by reducing the data source or turning off automatic updates and manually refreshing the Pivot Table.
' Solution:
Sub ManualUpdate()
With Sheets("YourSheetName").PivotTables("YourPivotTable")
.ManualUpdate = True
End With
End Sub
Replace "YourSheetName" and "YourPivotTable" with your specific names.
Note: With this setting, don't forget to manually refresh the pivot table when needed as it won't update automatically.
This said, remember that debugging requires a deep understanding of both systems and data. Being familiar with common issues and practical ways to solve them will help streamline your data analysis process when working with Excel Pivot Tables.
Leveraging Pivot Charts for Data Visualization
Introduction
A pivot chart is a graphical representation of a data summary displayed in a pivot table. Pivot Charts offer a visual interpretation of data and provide a simple way to convey comparisons, patterns, and trends. Pivot charts and pivot tables always remain connected.
Steps to Creating a Pivot Chart
For creating a pivot chart in excel, we need to have an existing pivot table. Here we are assuming that an excel worksheet containing a pivot table is already open.
Here are the steps to create a pivot chart:
Step 1: Selecting the Pivot Table
- Click anywhere in the Pivot Table.
This would automatically select the entire Pivot Table.
Step 2: Inserting Pivot Chart
- Click on the Ribbon’s “Insert” tab.
- Within the Charts group, click the Dialog Box Launcher (small corner arrow) next to PivotChart.
- In the Insert Chart dialog box, choose the chart type and click OK.
This will insert a blank pivot chart. Excel also displays the PivotChart Tools tabs (comprising Analyze and Design) on the Ribbon.
Step 3: Formatting the Pivot Chart
- Use the "Design" and "Format" tabs to modify the chart design and format.
- To add, remove, or manage the data in the chart, use the "PivotChart Fields" window.
Please note that any change to the pivot table data will affect the pivot chart as well, since they are interconnected.
Example: Sales Data Visualization
Assume we have a pivot table with the monthly sales summary - units sold and total sales amount by product category.
The pivot table structure:
Row Labels | Sum of Quantity | Sum of Total Sales |
---|---|---|
Category 1 | 10 | $700 |
Category 2 | 20 | $1500 |
Category 3 | 15 | $1200 |
Grand Total | 45 | $3400 |
Follow the steps mentioned above to create a pivot chart. Here we'll create a bar chart to visualize this sales data.
Implementation:
- Click on any cell in the pivot table.
- From the Ribbon’s “Insert” tab, click the Dialog Box Launcher next to PivotChart.
- In the Insert Chart dialog box, select "Bar Chart" and click "OK".
This will create a bar chart for quantity and total sales by category. You can customize the chart - add chart title, change bar colours, adjust scale, etc., based on your needs.
Conclusion
The pivot chart provides a visual perspective of the pivot table data, making it much easier to draw insights and present it to others. Remember, any change to the source data or pivot table will automatically reflect in the pivot chart.
Final Project: Real-World Application of Pivot Tables
This guide will focus on a practical, real-world example of using Pivot Tables for data analysis. Based on the modules you've completed, we assume that you already have Excel installed, a dataset prepared, and know how to create, manipulate, and debug Pivot Tables.
Scenario
Assume that we're working with an e-commerce business's sales data. The dataset includes variables like Order ID, Date of purchase, Product category, Product name, Price, Quantity, and Sales. We will analyze the dataset to answer real-world business questions.
Loading the Data
First, import your data into Excel, and ensure that all columns are properly labeled with their respective data categories.
File => Open => Browse => Select your file
Creating a Pivot Table
- Go to the Insert tab and click on the PivotTable.
- For "Choose the data that you want to analyze", select "Select a table or range".
- Make sure that your range includes all data cells (excluding totals if they exist).
- For "Choose where you want the PivotTable report to be placed", select "New worksheet".
- Click on OK.
Insert => PivotTable => Select a table or range => New Worksheet => OK
With your PivotTable created, ensure that your data fields appear in the PivotTable Field List panel.
Data Analysis
Let's answer some business questions:
What is the total revenue per product category?
Drag 'Product category' to Rows and 'Sales' to Values.
Drag 'Product category' to Rows Drag 'Sales' to Values
Excel will automatically sum up the 'Sales' for each 'Product category'.
What is the average price per product in each product category?
Remove 'Sales' from Values and add 'Price' to Values. For 'Price' in Values, click on the dropdown, go to Value Field Settings, and choose Avg.
Remove 'Sales' from Values Drag 'Price' to Values Value Field Settings => Avg
This will give us the average price per product in each product category.
What are the top 5 selling products overall based on quantity?
Clear all current fields, add 'Product name' to Rows, and 'Quantity' to Values.
Clear All Fields Drag 'Product name' to Rows Drag 'Quantity' to Values
Then, sort the Pivot table by 'Quantity’ in a descending order.
Sort By => Quantity => Descending
Finally, filter the Pivot table to show the top 5 rows.
Filter => Top 10 AutoFilter => Top 5 Items
What are the sales trend over time?
For this, you can create a Pivot Chart as follows:
Clear the fields, drag 'Date of purchase' to Rows, and 'Sales' to Values.
Clear All Fields Drag 'Date of purchase' to Rows Drag 'Sales' to Values
Then, order the dates in ascending order:
Sort By => Date of purchase => Ascending
Finally, create a Pivot Chart from the Pivot Table:
Analyze Menu => PivotChart
Choose Line Chart from the menu for a more clear presentation of sales trends.
This provides a practical real-world application of Pivot Tables in Excel, specifically for the purpose of conducting sales data analysis.