Skip to content

Pivot Tables and Aggregation

Summarising data by groups with pivot tables in spreadsheets, SQL and pandas, and avoiding aggregation mistakes.

Editorial team 1 min read

Aggregation — summarising data by groups — is the heart of most analysis.

Pivot Tables

Spreadsheet pivot tables let you drag fields into rows, columns and values to summarise quickly: sales by region and month, counts by category.

In SQL

GROUP BY with aggregate functions such as SUM, COUNT, AVG, MIN and MAX. HAVING filters groups.

In pandas

groupby with aggregation, and pivot_table for spreadsheet-style summaries.

Common Mistakes

  • Averaging averages: the average of regional averages isn't the overall average when regions differ in size. Use weighted averages or recompute from raw data.
  • Counting duplicates: use distinct counts where needed.
  • Mixing grains: joining daily data with monthly data inflates sums.
  • Summing ratios: add numerators and denominators separately, then divide.
  • Hidden filters: check pivot table filters before sharing.

Simpson's Paradox

A trend in every group can reverse when groups are combined. Look at both levels.

Check Totals

Make sure grand totals match the source data.

More in Data science & analytics

All Data science & analytics guides →
Data science & analytics Guide · 2 min

Descriptive Statistics Essentials

Mean, median, mode, spread and shape: the summary numbers every analysis starts with, and when each one misleads.

Data science & analytics 2 min read 6 Mar 2026

Data science & analytics Guide · 2 min

Probability Basics for Data Work

The probability ideas analysts use every day: events, conditional probability, independence and Bayes' theorem.

Data science & analytics 2 min read 5 Mar 2026

Data science & analytics Guide · 2 min

Common Probability Distributions

Normal, binomial, Poisson, exponential and more: recognising the shapes data takes and what they imply.

Data science & analytics 2 min read 4 Mar 2026

Data science & analytics Guide · 2 min

Hypothesis Testing Explained

Null hypotheses, p-values and significance: what a hypothesis test tells you, and the misunderstandings to avoid.

Data science & analytics 2 min read 3 Mar 2026