Advanced Excel Pivot Table Techniques

These texts, likely from a course on advanced pivot tables, provide a comprehensive guide to working with pivot tables in Excel. The content covers essential foundational skills, starting with creating a basic pivot table from raw data, ensuring the data is properly formatted and cleaned, and placing it into a table for easier management. It then moves into more advanced techniques, including importing data from external sources like text files and Access databases, demonstrating how to consolidate data from multiple sources, and showing various ways to group data within a pivot table by text, numbers, and dates. Finally, the texts explore formatting options for pivot tables, including applying built-in and custom styles, and handling error values and empty cells to present data clearly.

Fundamentals of Excel Pivot Tables

Based on the provided sources, here is a discussion of pivot table basics:

Pivot tables are described as the single most useful tool available in Excel for analyzing data. They are helpful for analyzing data in different ways, such as seeing the total sales accumulated by managers, sales in each category, sales by store, or sales between certain dates. The sources mention a recap of basic pivot table skills early in the course for those who haven’t used them recently or are not overly familiar with creating them from scratch.

Before creating a pivot table, it’s recommended to start with clean data. Cleaning data involves ensuring consistency and the absence of anomalies, such as blank rows, blank cells, inconsistent case, duplicates, and ensuring everything is formatted correctly. The sources also emphasize the importance of putting your data into a regular Excel table before creating a pivot table. This can be done by selecting the data and using Control + T, or by going to the Home ribbon, Styles group, and selecting “Format as Table”. When data is in a table, the “Table Design” contextual ribbon appears when clicked within the data. Another indicator is the presence of filter buttons at the top of each column. It’s also recommended to name your table for easier reading and understanding. Naming a table involves going to the Table Design ribbon, Properties group, and entering a name (without spaces, using underscores if needed), remembering to hit Enter. Putting data into a table also makes it easier to update pivot tables later when new data is added, as the table automatically expands to accommodate new rows.

To create a pivot table from scratch, make sure you are clicked within your data. You can use the “Summarize with PivotTables” option on the Table Design ribbon or go to the Insert ribbon and select the “PivotTable” button in the Tables group. Clicking either option opens a dialog box.

In this dialog box, you need to:

  1. Choose the data you want to analyze. Excel often intuitively picks up the table name or range you are clicked within. You can also choose to use an external data source.
  2. Choose where to place the pivot table report. It is generally suggested to keep your raw data separate from your pivot tables, so placing it on a new worksheet is recommended. You can rename the new sheet to something meaningful like “Pivot Table”.
  3. Click OK.

Once the pivot table is created, you will see an empty pivot table report area on the left and the PivotTable Fields pane on the right. If the pane is not visible, ensure you are clicked within the pivot table report area, or go to the PivotTable Analyze ribbon, Show group, and click “Field List”.

The PivotTable Fields pane lists all the column headings from your source data. Below the list of fields are four areas: Filters, Columns, Rows, and Values.

The core basic operation of building a pivot table is dragging any of these fields into any of these four areas.

  • Values: Fields dragged here are typically numeric and are used for calculations like sum, count, average, etc..
  • Rows: Fields dragged here display their unique values as rows in the pivot table.
  • Columns: Fields dragged here display their unique values as columns in the pivot table.
  • Filters: Fields dragged here create a filter above the pivot table, allowing you to filter the entire report by selecting specific items from that field.

Building a basic pivot table often involves some trial and error depending on the information you want to extract. For example:

  • To see total sales broken down by manager, drag “Sales” to Values and “Manager” to Rows.
  • To see total sales by category, drag “Sales” to Values and “Category” to Rows.
  • Dragging a field like “Manager” or “Product” between Rows and Columns changes the layout and how the data is presented.
  • Dragging “Category” to Filters allows you to filter the sales data shown in the report by selected categories.
  • Combining fields in Rows and Columns (e.g., Towns in Rows, Categories in Columns, Sales in Values) creates a cross-tabulated report.

The sources also mention the Recommended Pivot Tables option on the Insert ribbon, which analyzes your data and suggests potential pivot table layouts based on what might be useful. This can be a quick way to get a starting point, pre-populating the pivot table fields in the appropriate areas. However, this option cannot be used when combining data from multiple tables; in that case, you must use the standard “PivotTable” option and select the “Add this data to the Data Model” checkbox.

You can have more than one field in each area. When multiple fields are in the Rows or Columns areas, their order determines how the data is organized (e.g., organized by country first, then product, or product first, then country).

In summary, the basics involve preparing your data by cleaning it and putting it into a named Excel table, creating the pivot table using the Insert or Table Design ribbon, choosing the data source and location, and then dragging fields from the PivotTable Fields pane into the Rows, Columns, Values, and Filters areas to analyze and summarize your data.

Importing External Data for Pivot Tables

Importing data is a fundamental step when the information you need to analyze with a pivot table is not already in your current Excel workbook. The sources discuss various methods and considerations for bringing external data into Excel so it can be used effectively in pivot tables.

The primary location within Excel for accessing data import tools is the Data ribbon, specifically within the Get & Transform Data group. While the options available might differ slightly depending on your version of Excel, this is where you’ll find utilities for importing data from numerous sources.

The sources detail importing data from two main types of external sources:

  1. Text Files (like .txt or .csv):
  • One method is using the Get & Transform Data tool from the Data ribbon and selecting “From Text/CSV”. This opens a preview window where Excel attempts to detect the delimiter (the character separating columns, such as a tab, comma, or semicolon) and data types. You can change the delimiter if needed. From here, you can either “Load” the data directly or “Transform Data” using the Power Query Editor.
  • The Transform Data option is highlighted as a way to clean up data as part of the import process. In the Power Query Editor, you can check and correct data types (e.g., ensuring numbers are formatted as currency or dates are recognized as dates) and remove columns that are not needed for your analysis. Once satisfied, you can use “Close & Load” to import the data into an Excel table or “Close & Load To” to load it directly into a pivot table report.
  • Another way to import a text file is by opening it directly through the File menu. This often triggers the Text Import Wizard, which guides you through steps like defining the delimiter and setting column data formats. If you use the wizard or simply open a file, cleaning steps like correcting case, splitting columns, removing duplicates, and applying correct number formatting need to be performed after the data is in the worksheet using standard Excel tools. After cleaning, it’s recommended to put this data into a regular Excel table before creating a pivot table.
  1. Databases (like Microsoft Access):
  • To import from a database, you again use the Get & Transform Data group on the Data ribbon. Click the “Get Data” drop-down, select “From Database,” and then choose the relevant database type, such as “From Microsoft Access Database”.
  • You browse and select the database file, and Excel will connect and display the tables contained within it. You then select the specific table you want to import.
  • Similar to text files, you have the option to “Load” or “Transform Data”. Using “Transform Data” opens the Power Query Editor, allowing you to refine the data before importing, such as removing columns that are not relevant to your pivot table.
  • After transforming, the “Close & Load To” option can be used to directly import the cleaned data into a PivotTable Report on a new worksheet.

Regardless of how the data is imported, the sources strongly emphasize the importance of starting with or creating clean data. This means ensuring consistency, formatting data correctly, and removing anomalies like blank rows, blank cells, inconsistent casing, or duplicate entries. Cleaning can be done during the import process using Power Query or afterward using various Excel functions and tools.

Furthermore, after importing data into a worksheet (if not loaded directly into a pivot table), putting the data into a regular Excel table and naming it is recommended. This makes the data easier to reference, understand, and is particularly beneficial because a table automatically expands when new rows are added, making it much easier to update pivot tables built upon that data later on using the refresh function.

A more advanced scenario discussed is consolidating data from multiple tables into a single pivot table. This is necessary when your data is spread across different sets of information that need to be linked for combined analysis.

  • Each set of data must first be placed into a regular Excel table and named.
  • The tables must share a common field (referred to as a “key” or “primary key”) that logically links the data between them, like an “Order ID” shared across customer, order, and payment information.
  • To create a pivot table from multiple tables, you must use the standard “PivotTable” option on the Insert ribbon and select “Add this data to the Data Model” in the creation dialog box. The “Recommended Pivot Tables” option cannot be used for this.
  • Once the pivot table is created, you will see fields from the initial table in the PivotTable Fields pane but can click “All” to view fields from all imported tables.
  • The crucial next step is to create relationships between these tables based on their common key field. This is done via the PivotTable Analyze ribbon, using the “Relationships” button. By defining these links (e.g., linking the Order ID field in one table to the Order ID field in another), you enable the pivot table to draw data from different sources correctly.
  • After relationships are established, you can freely drag fields from any of the linked tables into the different areas of the pivot table to perform your analysis.

In essence, importing data involves using the tools on the Data ribbon to bring external information into Excel, potentially cleaning and transforming it using Power Query, ensuring it is in a clean Excel table format, and for analyzing multiple sources, creating relationships between the tables via the Data Model.

Essential Data Cleaning for Pivot Tables

Data cleaning and preparation are highlighted as absolutely crucial steps before analyzing data, particularly with pivot tables. The primary reason for this is that if your data is not clean, you might end up with inaccurate or misleading results.

Clean data is described as data that is consistent and free from anomalies. This includes ensuring there are:

  • No blank rows or blank cells.
  • No inconsistent casing (e.g., some text is all uppercase, some proper case).
  • No duplicate entries.
  • All data is formatted correctly, such as numbers, currencies, and dates.

Cleaning can be performed at different stages. If you are importing data using the “Get & Transform Data” tools, you can utilize the Power Query Editor to clean and transform data as part of the import process. Alternatively, if you open a file directly or data is already in Excel, you can clean it afterwards using standard Excel tools.

Here are some specific techniques and tools for cleaning data mentioned in the sources:

  • Checking and Correcting Data Types: When importing with Get & Transform Data, Excel attempts to detect data types, but you should verify and correct them in the Power Query Editor (e.g., changing numbers to currency or dates). If opening a file directly using the Text Import Wizard, you can set some formats, but often you need to correct them after import using the Home ribbon’s Number group. For values in a pivot table, number formatting is best done via Value Field Settings > Number Format to ensure consistency across the entire pivot table. Custom number formatting can be used to control how positive, negative, and zero values appear, including adding currency symbols, colors (like red or blue for negatives), or text (like “no data” for zeros).
  • Handling Blank Rows and Cells: Blank rows can be efficiently removed by selecting all columns, going to Find & Select > Go To Special > Blanks, and then using the Delete Sheet Rows option. For blank cells, you can select them using the same “Go To Special > Blanks” method and then enter a value (like 0) followed by Control + Enter to fill all selected blank cells at once. Pivot table options also allow you to specify what to show for empty cells (e.g., 0 or custom text).
  • Ensuring Consistent Case: You can use the PROPER function in a helper column to convert text to proper case. After using the function, it’s recommended to copy the helper column and paste values over the original data to replace the formulas with the cleaned text.
  • Removing Duplicates: Excel has a dedicated Remove Duplicates tool on the Data ribbon in the Data Tools group. You can select the columns Excel should check for duplicate information before removing entire rows that match across the selected columns.
  • Correcting Text Inconsistencies: The Find and Replace feature (Home ribbon > Find & Select, or Control + H) is useful for replacing inconsistent abbreviations or spellings with a standard version (e.g., replacing “mktg” with “marketing”).
  • Handling Non-Printable Characters, Line Breaks, and Erroneous Spaces: Text functions like CLEAN (removes non-printable characters and manual line breaks) and TRIM (removes excess spaces) can be used. These functions can even be combined with other functions like PROPER within a single formula in a helper column to address multiple issues at once. Again, pasting values over the original data is recommended after using formulas.
  • Splitting Data in Columns: The Flash Fill tool (Data ribbon > Data Tools group, or Control + E) is a quick way to split combined text, like separating a full name into first and last names, by recognizing a pattern from the first few manually entered examples.
  • Handling Error Values: Pivot table options allow you to specify what to display for error values (e.g., custom text like “no data” or a value like 0) instead of showing the raw error (like #N/A).

After the data has been cleaned, the final and critically important step before creating a pivot table is to put the data into a regular Excel table. This can be done by selecting the data and using Control + T or by using the “Format as Table” option on the Home ribbon. Putting data into a table provides several benefits:

  • It automatically adds filter buttons to column headers, making sorting and filtering easier.
  • It creates a Table Design contextual ribbon with tools specific to tables.
  • It’s recommended to name your table from the Table Design ribbon > Properties group. Table names (like sales_data) are easier to read and understand than cell ranges when creating pivot tables.
  • Crucially for pivot tables, when you add new data (rows) to the bottom of a table, the table automatically expands to include the new data. This makes updating pivot tables built on that table much simpler, as you only need to use the Refresh function on the PivotTable Analyze ribbon to incorporate the new data. If the data wasn’t in a table, you would have to manually change the pivot table’s data source to include the new rows, which takes much longer.

In summary, thorough data cleaning and preparation are essential for accurate pivot table analysis, involving various techniques to address inconsistencies, errors, and formatting issues, and culminating in placing the cleaned data into a named Excel table for ease of use and future updates.

Creating Excel Pivot Tables from Single or Multiple Tables

Creating pivot tables is the primary goal after you have prepared and imported your data, as discussed previously. Pivot tables are considered the single most useful tool in Excel for analyzing data. This course is designed to guide you through utilizing the pivot table options to create meaningful analysis.

Before you begin creating a pivot table, it is crucial that your data is clean and, importantly, placed within a regular Excel table. As we’ve discussed, clean data is consistent and free from anomalies like blank rows, blank cells, inconsistent casing, or duplicates, and everything is formatted correctly. Putting your data into a regular table (Control + T or Home ribbon > Format as Table) is a vital final step. Naming your table (Table Design ribbon > Properties group) is also highly recommended for clarity, making the data easier to read and understand. A key benefit of using a table for pivot tables is that it automatically expands to include new data added to the bottom, making it simple to refresh your pivot table to incorporate the new information later.

There are a few different ways to initiate the process of creating a pivot table from your prepared data:

  1. Using the Table Design Ribbon: If your data is in an Excel table and you are clicked inside it, you can use the “Summarize with PivotTable” option found on the Table Design contextual ribbon.
  2. Using the Insert Ribbon: A more standard method is to go to the Insert ribbon and click the “PivotTable” button, located in the Tables group. This is the first option in that group.
  3. Using Recommended PivotTables: Excel offers a “Recommended PivotTables” option on the Insert ribbon, right next to the standard “PivotTable” button. This feature analyzes your data and suggests potential pivot table layouts that might be useful, such as summing profit by country or month. Choosing one of these suggested options can create a pre-populated pivot table very quickly. However, this method cannot be used if you need to analyze data from multiple tables simultaneously.

Regardless of whether you use the Table Design or Insert ribbon’s standard “PivotTable” option, clicking it will open the “Create PivotTable” dialog box. Here, you need to make two main choices:

  • Choose the data that you want to analyze: If you were clicked inside a named Excel table when you opened the dialog, Excel will intuitively select that table name as the data source. You can also choose to use an external data source.
  • Choose where you want the PivotTable Report to be placed: The recommendation is always to place the pivot table on a new worksheet to keep your raw data separate. You can also choose an existing worksheet and specify the location.

Clicking “OK” (after specifying data and location) will create a new worksheet (or navigate you to the chosen location) containing a blank pivot table report on the left side. On the right side, you will see the PivotTable Fields pane. If this pane is not visible, ensure you are clicked within the blank pivot table report area. If it still doesn’t appear, it might have been accidentally closed; you can get it back by going to the PivotTable Analyze ribbon, clicking “Field List” in the Show group.

The PivotTable Fields pane is essential for building your pivot table. It lists all the column headings from your data source as available fields. Below the field list, there are four distinct areas:

  • Filters: Fields placed here allow you to filter the entire pivot table report.
  • Columns: Fields dragged here become the column headings in your pivot table.
  • Rows: Fields dragged here become the row headings in your pivot table.
  • Values: Fields placed here are the numbers or values you want to summarize (e.g., sum of sales, count of units). By default, Excel often sums numeric fields, but you can change the calculation type in the Value Field Settings.

Building the Pivot Table: The core process of creating a pivot table involves simply dragging fields from the list at the top of the pane into the four areas below. There’s often a bit of trial and error involved depending on the analysis you need. For example, to see the total sales by manager, you would drag the “Sales” field into the Values area and the “Manager” field into the Rows area. The pivot table report will update as you drag and drop fields. You can easily move fields between areas to change the layout and analysis. Placing multiple fields in the Rows or Columns areas will create nested levels of detail. The order of fields within an area matters for the hierarchy of the report (e.g., Country then Product, or Product then Country).

Excel provides helpful automatic grouping for date fields when you drag them into Rows or Columns, often breaking them down into Years, Quarters, and the Date itself, allowing you to easily analyze data by different time periods. You can expand or collapse these groups or customize which levels (Years, Quarters, Months, Days) are displayed via the Group Field option on the PivotTable Analyze ribbon.

A more advanced scenario is creating a pivot table from multiple tables. This is necessary when the data you need for analysis is spread across different sets of information, each in its own table. To do this:

  1. Ensure each set of data is in a regular Excel table and named meaningfully.
  2. The tables must share a common field (like an “Order ID”) that acts as a “key” to link the data logically between them.
  3. When creating the pivot table, you must use the standard “PivotTable” option from the Insert ribbon. In the “Create PivotTable” dialog box, after selecting your first table and location, you must select the option “Add this data to the Data Model”.
  4. After the pivot table is created, the PivotTable Fields pane will initially show fields from the table you were in, but clicking “All” will display fields from all imported tables that were added to the Data Model.
  5. The critical next step is to create relationships between these tables based on their common field. This is done from the PivotTable Analyze ribbon using the “Relationships” button. In the “Manage Relationships” dialog, you click “New” and define the links, specifying which table and column relate to which other table and column (e.g., linking the “Order ID” in the ‘Order Info’ table to the “Order ID” in the ‘Payment Info’ table).
  6. Once relationships are established, you can freely drag fields from any of the linked tables into the Filters, Columns, Rows, and Values areas to build your consolidated pivot table.

Finally, it’s a good practice to name your pivot table itself (PivotTable Analyze ribbon > Properties group) to keep everything organized and easy to reference, similar to naming tables. You can also drill down into any number in your pivot table by double-clicking it, which will open a new sheet showing the underlying data that makes up that total. For large data sets, you can use the “Defer Layout Update” option at the bottom of the PivotTable Fields pane to organize your fields before updating the pivot table, which can improve performance.

Excel Custom Formatting: Numbers and Styles

Based on the sources and our conversation, custom formatting in Excel, particularly within pivot tables, refers primarily to controlling the visual appearance of numbers and values, and also extending to the overall look and feel of the pivot table itself through custom styles.

Custom Number Formatting in Pivot Tables

Custom number formatting is a powerful tool for controlling exactly how numbers and values are displayed in your pivot table report. While you can apply basic formatting like currency or accounting format through the Value Field Settings dialog box, custom formatting allows for much greater control.

To apply custom number formatting in a pivot table, you should right-click anywhere in your numeric data within the pivot table, go down to Value Field Settings, and then select Number Format from there. This is a better approach than using the formatting options on the Home ribbon, which might lead to problems later. From the Format Cells dialog that appears, you can select the Custom category.

The key to understanding custom number formatting is remembering a simple rule: the format string is typically broken into four parts separated by semicolons. These parts define how different types of values are displayed:

  1. Positive numbers: The format before the first semicolon.
  2. Negative numbers: The format between the first and second semicolon.
  3. Zero values: The format between the second and third semicolon.
  4. Text values: The format after the third semicolon.

You don’t necessarily have to define all four parts every time.

Examples of Custom Number Formatting from the Sources:

  • Formatting Negative Numbers: By default, negative numbers might show in brackets. You can use custom formatting to show them with a minus sign and/or in a different color like red or blue. For example, the format #,##0.00;[Red]-#,##0.00 formats positive numbers with a thousand separator and two decimal places, while negative numbers are shown in red with a minus sign and the same number format. You can add currency symbols to these formats as well.
  • Formatting Zero Values: You can define how cells with a value of zero should appear. This could be simply 0 or you could display text like “no data” by putting the desired text in quote marks in the third section of the format string (e.g., Positive;Negative;”no data”).
  • Combining Text and Values: You can include text along with the numeric display. For example, you could add the word “loss” next to negative numbers by including “loss” in quote marks within the negative number part of the format string.
  • Using Placeholders (# vs. 0): Within the format parts, symbols like # (hash) and 0 (zero) are used as placeholders for digits. A # is a variable placeholder, only displaying digits if they are present, while a 0 is fixed, forcing a digit (zero if necessary) to be displayed. This is useful for maintaining consistent length for numbers, such as formatting item numbers like “1” and “100” to “0001” and “0100” using 0000 as the custom format.

It is important to remember that applying custom formatting only changes the visual appearance of the number; the underlying value in the cell remains unchanged. This means you can format a zero value to show as “no data,” but Excel still recognizes it as a zero for calculations.

If you want to revert a cell or range back to its original state after applying custom formatting, you can use the General format. Custom formats you create are saved in the Custom formatting list within the workbook for potential reuse.

Custom Pivot Table Styles

Beyond number formatting, the sources also discuss creating custom pivot table styles. This refers to defining the visual look of different elements within the pivot table itself, such as header rows, banded rows or columns, first column, grand totals, etc., including aspects like font styles (e.g., italics), fill colors, and borders.

You can access options to create a new custom style from the PivotTable Design ribbon, in the PivotTable Styles group, by clicking the “more” button and selecting New PivotTable Style. This opens a dialog where you can name your style and then select and format each individual element of the pivot table.

Unlike custom number formats, custom pivot table styles are typically saved within the workbook where they were created and are not automatically available in other workbooks. However, you can copy a custom style to another workbook by copying a worksheet containing a pivot table with that style applied into the new workbook.

Advanced Pivot Tables Tutorial in Excel – 2.5 Hour Pivot Table Excel Course

By Amjad Izhar
Contact: amjad.izhar@gmail.com
https://amjadizhar.blog


Discover more from Amjad Izhar Blog

Subscribe to get the latest posts sent to your email.

Comments

Leave a comment