Home | Power BI | Excel | Python | SQL | Generative AI | Visualising Data | Analysing Data
We can use either pivot tables or formulas to summarise data. Both approaches have their pros and cons and the best approach depend on the circumstances.
In this lab we use a fictitious dataset of about 700 transactions over a 2 year period. The company sells about six different types of product to customers in about 5 countries. The data has some categorical fields such as Country, Segment and Product that we may want to group by. It also has some numeric fields, such as Quantity and Discount, that we may want to aggregate (sum or count).
The data also has a few other important columns
First we format our data as an Excel table named Store. This will make all subsequent operations simpler.
Next we add three useful calculated columns to the Store table based on these formulas:
We start by creating some pivots on the Store table, for example, Sales and Number of Transactions (both in the Values area) by Country (in the Rows area) and Product (in the Columns area). We experiment with different configurations by putting one or more categorical fields into the Rows and/or Columns areas and one or more numeric fields into the Values area.
We experiment with the appearance and formatting of our pivot tables, for example,
We experiment with conditional formats, for example
Once we have more than one categorical fields on either the Rows or Columns areas, we can experiment with expand and collapse sections.
The pivot table will order the categorical values in alphabetical order. We may want to change this either by:
The Store data provides a Date column, but we may want to group the pivot table at a higher level, for example by Year and Month. We can do this in two ways:
We filter the data in the pivot either by:
Slicers have some advantages over fields in the Filter area
We look at several other useful features of pivot tables
Pivot tables are great to get a fast simple summary of our data and to explore the data quickly. However they have limitation, especially when it comes to creating a polished report. Using formulas is an alternative approach, and in some cases a better approach for a few reasons:
This approach uses functions such as UNIQUE, SUM, FILTER, SUMIFS and COUNTIFS.
This approach can also takes advantage of dynamic array formulas Since the row and column headers are created by a spill function, we can pass the array of row or column header values as arguments into the SUMIFS function to generate a row / column / grid of values rather than a single value. This avoids the need for to write mixed references in formulas and also the need to copy formulas.
In this exercise, we use functions to achieve the same results as the pivot tables that we have built previously. We use these steps
We also check if these formulas adapt well if the Store data changes, for example, there is no need to change the formula if the Store data expands to new rows or new countries are added
Excel has some very new functions GROUPBY and PIVOTBY. These can create a pivot table in single formula. Note that these may not yet be available in students’ version of Excel 365
We create a calculation which would be impossible to do with pivot tables. This is the number of orders for each country. The OrderId is not a unique field so we have to use an approach of counting the distinct values of OrderId.