Pivot Tables, Explained

After reading this you will know exactly how a pivot table turns a flat CSV into a cross-tabulated summary, how each aggregation is computed cell by cell, and how to read the totals without fooling yourself.

A pivot table takes many rows and collapses them into a compact grid. You pick a field for the rows, a field for the columns, one field to aggregate, and a rule for combining values (count, sum, average, min or max). The tool then walks every row of your CSV, drops it into the right cell of the grid, and applies the rule.

Here is the hook. Suppose you have 500 sales records with a region column and an amount column. You want to know total sales per region. That is a pivot: rows = region, values = amount, aggregation = sum. What was 500 lines of raw data becomes a four-line answer.

What a pivot table actually does

Think of your CSV as a stack of index cards, one per row. A pivot table sorts those cards into bins. The row field decides which shelf a card goes on. The column field decides which slot on that shelf. Once every card is filed, the tool reduces each slot to a single number using the aggregation you chose.

Two fields define the grid. If you leave the column field empty, you get a single stack of shelves: one row per group, one number per row. That is a grouped summary. Add a column field and the grid becomes two-dimensional, with a value in every intersection.

Row field
The category that labels each row of the output. Distinct values become distinct rows.
Column field
The category that labels each column. Optional. Distinct values become distinct columns.
Value field
The column whose numbers get aggregated. For count, any column works; the values are just tallied.
Aggregation
The rule that reduces the group of matching rows to one number: count, sum, average, min or max.

When to use it, and when not

Reach for a pivot when you have one row per event or record and you want a summary by category. Sales by region and quarter, error counts by service and day, average response time by endpoint: all pivots.

Do not use a pivot when you actually want to keep every row and only reshape or filter it. If you need to sort, hide columns or pull out a subset of rows, that is a job for the CSV Viewer & Editor. A pivot is lossy on purpose: after aggregation the individual rows are gone.

Watch the cardinality of your column field. If you put a field with 800 distinct values (like a customer ID) into the column slot, you get an 800-column table that is unreadable and slow. Column fields work best with a handful of categories.

The five aggregations and their math

For a cell, let the matching values be x_1, x_2, \dots, x_n. Each aggregation reduces that set to one number.

\text{count} = n \qquad \text{sum} = \sum_{i=1}^{n} x_i \qquad \text{avg} = \frac{1}{n}\sum_{i=1}^{n} x_i

Here n is how many rows fell into the cell, and x_i is the value from row i. Min and max are just the smallest and largest of the x_i.

Count is special. It tallies rows and never looks at whether the value is a number, so it works on any column. Sum and average require numeric values. Cells that do not parse as numbers are skipped, which means n for a sum can be smaller than the count of rows in the same cell. That gap is a frequent source of confusion, so hold onto it.

An empty cell in the output means no rows matched that row and column combination. A cell showing 0 for a sum means rows matched but their values summed to zero. Those are different facts.

A worked example with the demo data

Load the demo. The sample is a small sales table:

Sample CSV: one row per sale
regionproductquarteramount
NorthWidgetQ1100
NorthGadgetQ1200
NorthWidgetQ2150
SouthWidgetQ1120
SouthGadgetQ2300
SouthGadgetQ180

Sum of amount by region and product

Set rows = region, columns = product, value = amount, aggregation = sum.

  1. File each row. North+Widget gets rows 1 and 3 (100 and 150). North+Gadget gets row 2 (200). South+Widget gets row 4 (120). South+Gadget gets rows 5 and 6 (300 and 80).
  2. Sum each cell. North+Widget = 100 + 150 = 250. North+Gadget = 200. South+Widget = 120. South+Gadget = 300 + 80 = 380.
  3. Add totals. Row total North = 250 + 200 = 450. Row total South = 120 + 380 = 500. Column total Widget = 250 + 120 = 370. Column total Gadget = 200 + 380 = 580. Grand total = 950.
Result: sum of amount, with totals
regionWidgetGadgetTotal
North250200450
South120380500
Total370580950

Check the arithmetic two ways: the row totals add to 450 + 500 = 950, and the column totals add to 370 + 580 = 950. If those two do not match, something dropped a value. They should always agree for count and sum.

Two bars per region, one per product. North leans toward Widget; South leans hard toward Gadget.

See how the aggregation changes the answer

The same grid tells a different story under each rule. Take the North+Widget cell, which holds the values 100 and 150. Count gives 2, sum gives 250, average gives 125, min gives 100, max gives 150. The bins never move; only the reduction changes.

For the North+Widget cell (values 100 and 150): count = 2, sum = 250, average = 125, min = 100, max = 150. For South+Gadget (values 300 and 80): count = 2, sum = 380, average = 190, min = 80, max = 300.

Reading and interpreting the result

Read a pivot cell as a sentence. The cell at row North, column Widget, sum of amount, reads: "The total amount for North Widget sales is 250." Always name the aggregation out loud, because 250 means nothing until you know it is a sum and not a count or an average.

Totals deserve care. Row and column totals are trustworthy for count and sum: they are the sum of the cells. For average they are not. The average of the North row is not (125 + 200) / 2 = 162.5; the true average across all three North rows (100, 150, 200) is 450 / 3 = 150. An average of averages ignores how many rows sit behind each cell. When you need a grand average, aggregate the raw rows, do not average the cell averages.

If you plan to compute averages over combined groups, keep both a count pivot and a sum pivot. Divide the summed grand total by the counted grand total to get the correct weighted average. For the demo North row: 450 / 3 = 150.

Common mistakes

The mistakes below are the ones that quietly change your numbers.

  • Non-numeric values in a sum. A cell holding 1,200 with a thousands separator, or $300, or N/A, does not parse as a number and is skipped. Your sum comes out low and you never see the dropped rows. Clean the column first.
  • Trailing spaces splitting a group. "North" and "North " are two different row labels. You get two North rows that should have been one. Trim whitespace before pivoting.
  • Case sensitivity. Widget and widget land in separate columns. Normalize case if they mean the same thing.
  • Averaging averages. Covered above. It is the most common way to get a plausible but wrong headline number.
  • Too many columns. A high-cardinality column field produces a table nobody can read. Move that field to rows, or leave the column field empty.

Related tools

Prepare and inspect your data before and after pivoting. Use the CSV Viewer & Editor to trim whitespace and drop bad rows first. If your data starts in a spreadsheet, run it through the Excel → CSV Converter to get clean CSV per sheet. Need the summary as structured data? Send the CSV output through the CSV ↔ JSON Converter. To paste the result into docs, the Markdown Table Generator turns rows into an aligned table. If the source contains personal data, mask it with the Data Anonymizer before you share the pivot. And if your data lives in columnar files, the Parquet & Feather Preview lets you peek inside first.

Frequently asked questions

Why is my sum smaller than I expected?

Sum and average skip cells that are not numbers. Values with currency symbols, thousands separators, blank cells or text like N/A are ignored. Compare a count pivot against a sum pivot on the same fields: if the count is higher than the number of values that summed, you have non-numeric entries.

Can I leave the column field empty?

Yes. That gives you a grouped summary with one row per distinct value of the row field and a single value column. It is the simplest and often the most readable form.

Do the row totals and column totals have to match?

For count and sum, yes. Both add up to the grand total, so they must be equal. In the demo, 450 + 500 = 950 and 370 + 580 = 950. For min, max and average, totals across cells are not meaningful and should not be summed.

Does my data get uploaded anywhere?

No. The pivot runs entirely in your browser. Your CSV never leaves your device, which matters when the data contains customer or employee records.

How do I get a correct average over a whole row?

Do not average the cell averages. Take the summed total for the row and divide by the counted total for the row. For the North row in the demo: sum 450 over count 3 equals 150.