Menu

Pivot Table in Excel: How to Create One, Step by Step

A pivot table groups the rows of a table by a category and totals a number for each one, without formulas: Insert > PivotTable, then drag fields to Rows and Values. Here are the steps, the four areas explained, and the same summary built with formulas.

Every sheet on this page is live: change a number or a formula and it recalculates.

A pivot table groups the rows of a table by a category, such as Region, and totals a number, such as Sales, for each group, without formulas. To create one, click a cell in the data, go to Insert > PivotTable, press OK, and drag Region to Rows and Sales to Values. The sheet below is not a pivot table: it builds the same summary with formulas, so you can watch the totals change.

The same summary with formulas
F2
ABCDEFG
1RegionProductSalesRegionSales% of total
2NorthApple120North45549%
3SouthPear85South30533%
4NorthPear240East17018%
5EastApple60
6SouthApple150
7NorthApple95
8EastPear110
9SouthPear70
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

UNIQUE lists each region once and SUMIF totals it: North 455, South 305 and East 170, which is 49%, 33% and 18% of the 930 in all. Change C3 to 185 and the South total and all three percentages follow at once. A pivot table would show the same numbers, but only after you refresh it.

How to create a pivot table

Before you start, check the source data: one header row with a name in every column, one record per row, no blank rows or columns in the middle, and no subtotal rows.

  1. Click any cell in the data.
  2. Go to Insert > PivotTable (on some versions Insert > PivotTable > From Table/Range).
  3. Excel fills in the range. Choose New Worksheet and press OK.
  4. A blank pivot table appears with the PivotTable Fields pane on the right, listing your column headers.
  5. Drag Region into the Rows box and Sales into the Values box. The pivot table shows each region once with Sum of Sales next to it, and a Grand Total row.
  6. To change what is shown, drag fields between the boxes or out of the pane.

If you are not sure where to start, Insert > Recommended PivotTables shows a few ready-made layouts for your data. On a Mac the menu is the same: Insert > PivotTable.

Rows, Columns, Values and Filters

The PivotTable Fields pane has four boxes, and every pivot table is a choice of which column goes into which box:

  • Rows: the categories down the left side, one row per distinct value (Region).
  • Columns: categories across the top, one column per distinct value (Product).
  • Values: the numbers to calculate for each combination. Sum is the default for a numeric column; Count, Average, Max, Min and others are in Value Field Settings.
  • Filters: a field the whole pivot table is filtered by, shown as a drop-down above it.

With Region in Rows, Product in Columns and Sales in Values, the pivot table for the data above looks like this:

Sum of Sales   Column Labels
Row Labels     Apple   Pear   Grand Total
East              60    110           170
North            215    240           455
South            150    155           305
Grand Total      425    505           930

The formula version of that layout lists the regions down with UNIQUE, the products across with TRANSPOSE(UNIQUE()), and calculates every cell of the grid with one SUMIFS that takes the two lists as its criteria:

Region by product, with formulas
F2
ABCDEFG
1RegionProductSalesApplePear
2NorthApple120North215240
3SouthPear85South150155
4NorthPear240East60110
5EastApple60
6SouthApple150
7NorthApple95
8EastPear110
9SouthPear70
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

E2 spills North, South and East down, F1 spills Apple and Pear across, and the SUMIFS in F2 fills the 3 by 2 grid between them: one total for each pair of a region and a product. Change B5 from Apple to Pear and both East cells change. The order here is the order the values first appear in; a pivot table sorts its labels alphabetically.

Count, average or percentage instead of sum

In the pivot table, click the field in the Values box and choose Value Field Settings. The Summarize Values By tab switches between Sum, Count, Average, Max and Min; the Show Values As tab turns the numbers into % of Grand Total, % of Column Total, a running total and others. Each formula has a direct counterpart:

Count and average per region
E2
ABCDEFG
1RegionProductSalesRegionOrdersAverage
2NorthApple120North3151.7
3SouthPear85South3101.7
4NorthPear240East285.0
5EastApple60
6SouthApple150
7NorthApple95
8EastPear110
9SouthPear70
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

North has 3 orders averaging 151.7, South 3 averaging 101.7, East 2 averaging 85.0. The % of Grand Total column is in the first sheet on this page.

Filter the summary by one product

The Filters box puts a drop-down above the pivot table. The formula version is a cell with a drop-down list and SUMIFS, which adds one more condition to SUMIF. Pick a product in F1:

Sales of one product by region
F1
ABCDEF
1RegionProductSalesProduct:Apple
2NorthApple120
3SouthPear85RegionSales
4NorthPear240North215
5EastApple60South150
6SouthApple150East60
7NorthApple95
8EastPear110
9SouthPear70
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

With Apple chosen, North shows 215, South 150 and East 60. Pick Pear and they change to 240, 155 and 110. See SUMIFS for more conditions and the drop-down list page for how to add the list in Excel.

Refresh a pivot table

A pivot table keeps a copy of the source data (the pivot cache) and does not recalculate when a cell in the source changes. After editing the data:

  • Right-click anywhere in the pivot table and choose Refresh, or press Alt+F5 on Windows.
  • Data > Refresh All (Ctrl+Alt+F5) refreshes every pivot table in the workbook.
  • To refresh every time the file opens, right-click the pivot table, choose PivotTable Options, and on the Data tab tick Refresh data when opening the file.

New rows added under the source range are not included, even after a refresh. Change the range under PivotTable Analyze > Change Data Source, or, better, turn the source into a table before creating the pivot table: select the data and press Ctrl+T, or use Insert > Table. A table grows when you add rows, and the pivot table picks them up on the next refresh.

Total every region with one formula

One formula for all regions
F2
ABCDEF
1RegionProductSalesRegionSales
2NorthApple120North
3SouthPear85South
4NorthPear240East
5EastApple60
6SouthApple150
7NorthApple95
8EastPear110
9SouthPear70
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: In F2, total the sales of every region listed in E2:E4 with one formula.

The answer spills 455, 305 and 170. Giving SUMIF the whole list E2:E4 as its criteria returns one total per region, so there is nothing to fill down. Excel 2019 and older have neither UNIQUE nor spilling: type the regions in E2:E4 and fill =SUMIF($A$2:$A$9,E2,$C$2:$C$9) down. Without the $ signs the ranges move down with each row and the totals come out wrong.

GROUPBY and PIVOTBY: a pivot table in one formula

Excel for Microsoft 365 has two functions that build a whole summary from one formula and recalculate like any formula, with no refresh. They need a current Microsoft 365 subscription. For the data above:

=GROUPBY(A2:A9,C2:C9,SUM)

East      170
North     455
South     305
Total     930
=PIVOTBY(A2:A9,B2:B9,C2:C9,SUM)

          Apple   Pear   Total
East         60    110     170
North       215    240     455
South       150    155     305
Total       425    505     930

GROUPBY takes the row field, the values and the function (SUM, COUNTA, AVERAGE, MAX, PERCENTOF). PIVOTBY adds a column field between them. Both sort the labels and add total rows, like a pivot table.

Pivot table or formulas: which to use

Pivot tableFormulas (UNIQUE + SUMIF)
SetupDrag and drop, no typingType a formula per column
UpdatesNeeds RefreshRecalculates on every change
New categoriesAppear after a refreshAppear in the UNIQUE spill at once
ExploringRearrange in seconds, drill down by double-clicking a numberRewrite the formulas
Grouping dates by month or yearBuilt in (right-click a date > Group)Needs MONTH, YEAR or TEXT
Layout and formatFixed pivot layoutAny layout, any cell can feed a report or chart

Use a pivot table to explore data and answer a question once; use formulas for a summary that sits in a report, feeds other formulas, and must always be current. To check a pivot table's numbers, rebuild one cell of it with SUMIFS: if the two disagree, the pivot table usually needs a refresh or its source range is too short.

Frequently Asked Questions

What is a pivot table in Excel?

A summary of a table that groups the rows by the values of one or more columns and calculates a total, count or average for each group. You build it by dragging column names into four areas (Rows, Columns, Values, Filters), and it does not change the source data.

How do I create a pivot table in Excel?

Click a cell in the data, go to Insert > PivotTable, choose New Worksheet and press OK. In the PivotTable Fields pane, drag a category (Region) to Rows and a number column (Sales) to Values.

Why does my pivot table not show new data?

A pivot table does not update by itself. Right-click it and choose Refresh, or use Data > Refresh All (Ctrl+Alt+F5). If new rows were added below the source range, also change the range under PivotTable Analyze > Change Data Source, or turn the source into a table with Ctrl+T so it grows on its own.

How do I make a pivot table count instead of sum?

Click the field in the Values area, choose Value Field Settings and pick Count. Excel picks Count by default when the column holds text or has empty cells, which is why a pivot table sometimes shows counts where you expected totals.

Can I make a pivot table with formulas?

Yes. =UNIQUE(A2:A9) in E2 lists each category once, and =SUMIF(A2:A9,E2:E4,C2:C9) in F2 totals each one. In Microsoft 365, =GROUPBY(A2:A9,C2:C9,SUM) returns the whole summary in one formula.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED