intermediate 5 min read

QUERY PIVOT in Google Sheets (Pivot-Style Reports)

Learn how to use QUERY PIVOT in Google Sheets to create cross-tabulated reports. Syntax, step-by-step examples, and tips for pivot-style summaries.

SB

Sheets Bootcamp

March 10, 2026 · Updated November 5, 2026

Reviewed by Ryan

Quick Answer

PIVOT turns the unique values of one column into column headers: =QUERY(A1:G11, "SELECT B, SUM(F) GROUP BY B PIVOT C"). This gives one row per salesperson and one column per region, each holding total revenue. Sherlock Holmes’s Baker Street total is $834.85, and combinations with no sales stay blank. Put PIVOT after GROUP BY, and put WHERE before GROUP BY to filter rows first.

QUERY PIVOT in Google Sheets turns unique values from one column into separate column headers, creating a cross-tabulated report inside a QUERY formula. It works like a formula-based pivot table, rows represent one dimension, columns represent another, and the cells contain aggregated values. We’ll cover the syntax, walk through building pivot reports, and show how PIVOT combines with WHERE and GROUP BY.

In This Guide

PIVOT Syntax

PIVOT goes after GROUP BY in the query string:

Formula
=QUERY(data, "SELECT groupColumn, AGGREGATE(valueColumn) GROUP BY groupColumn PIVOT pivotColumn")
PartRoleExample
groupColumnBecomes the row labelsB (Salesperson)
AGGREGATE(valueColumn)The calculation in each cellSUM(F) (total Revenue)
pivotColumnUnique values become column headersC (Region)

Important

When SELECT includes a plain column like B, you need GROUP BY. The grouped column provides row labels, the aggregated column provides cell values, and the pivot column provides new column headers. Without a plain column, SELECT SUM(F) PIVOT C works without GROUP BY and returns one row of totals.

Try it yourself

Question 1 of 3

3 quick questions. No account needed.

In A11, write a QUERY on A1:D9 with one row per Helper and one column per Shift, showing total Cars. Use GROUP BY A and PIVOT B.

A
B
C
D
E
F
G
H
I
J
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Helper
Shift
Job
Cars
Jo
AM
Wash
14
Max
AM
Vacuum
9
Sam
PM
Wax
11
Jo
PM
Vacuum
6
Max
PM
Wash
12
Sam
AM
Wash
10
Jo
AM
Wax
7
Max
AM
Wax
5
A11

How to Create a QUERY PIVOT: Step-by-Step

We’ll use the same sales records table from the QUERY guide. The data is in A1:G11 with 10 transactions.

Sample Data

ABCDEFG
1DateSalespersonRegionProductUnitsRevenueCommission
21/5/2026Sherlock HolmesBaker StreetListening Device12$239.88$24.00
31/7/2026Irene AdlerScotland YardForensic Chemistry Set8$360.00$36.00
41/8/2026Inspector LestradeBaker StreetPocket Watch15$525.00$52.50
51/10/2026Sherlock HolmesBaker StreetField Binoculars5$325.00$32.50
61/12/2026Mycroft HolmesScotland YardCipher Decoder20$570.00$57.00
71/14/2026Irene AdlerWhitehallMagnifying Glass25$624.75$62.50
81/15/2026Inspector LestradeScotland YardListening Device10$199.90$20.00
91/18/2026Sherlock HolmesBaker StreetDisguise Kit3$269.97$27.00
101/20/2026Mycroft HolmesWhitehallBrass Telescope8$336.00$33.60
111/22/2026Irene AdlerScotland YardLockpick Set6$330.00$33.00

Sales records table with 10 transactions in Google Sheets

1

Review your data range

Your data lives in A1:G11. Row 1 is the header. You want to see total revenue per salesperson, broken down by region, a cross-tabulation with salespeople as rows and regions as columns.

2

Create a basic PIVOT

Select an empty cell and enter:

Formula
=QUERY(A1:G11, "SELECT B, SUM(F) GROUP BY B PIVOT C")

QUERY groups by Salesperson (B), sums Revenue (F), and pivots on Region (C). The result has four columns: Salesperson, then one column for each unique region (Baker Street, Whitehall, Scotland Yard). Sherlock Holmes’s Baker Street total is $834.85, and cells where a salesperson has no transactions in a region are left blank.

QUERY PIVOT showing revenue per salesperson by region

3

Add WHERE to filter before pivoting

Enter:

Formula
=QUERY(A1:G11, "SELECT B, SUM(F) WHERE F > 200 GROUP BY B PIVOT C")

This filters out Inspector Lestrade’s $199.90 Scotland Yard transaction before creating the pivot. Inspector Lestrade’s Scotland Yard column is now blank because his only Scotland Yard transaction was below $200.

QUERY PIVOT with WHERE filtering revenue over $200

Tip

WHERE runs before GROUP BY and PIVOT. Use it to exclude outliers or irrelevant rows from your summary before the cross-tabulation is built.

PIVOT with COUNT

COUNT counts the number of transactions instead of summing values:

Formula
=QUERY(A1:G11, "SELECT B, COUNT(F) GROUP BY B PIVOT C")

This shows how many transactions each salesperson made in each region. Sherlock Holmes has 3 transactions in Baker Street. His Scotland Yard and Whitehall cells are blank, not 0, because he has no transactions there.

QUERY PIVOT with COUNT showing transaction counts by region

PIVOT with AVG

AVG calculates the average value per cell:

Formula
=QUERY(A1:G11, "SELECT B, AVG(F) GROUP BY B PIVOT C")

This returns the average revenue per transaction for each salesperson-region combination. Mycroft Holmes’s average in Scotland Yard is $570.00 (one transaction), while his Whitehall average is $336.00.

QUERY PIVOT vs Pivot Tables

Both create cross-tabulated summaries, but they work differently:

FeatureQUERY PIVOTPivot Table
Output locationIn the same sheet as a formulaSeparate sheet or overlay
Auto-updatesYes, on data changeYes, on refresh
Combines with filtersWHERE in same formulaSeparate filter controls
Multiple aggregatesYes, each gets its own columnsMultiple in one pivot
Custom formulasFull QUERY syntaxLimited calculated fields
Learning curveText-based query stringPoint-and-click editor

Use QUERY PIVOT when you want a formula-driven summary that stays on the same sheet. Use a pivot table when you need interactive slicing or a point-and-click interface.

Common Mistakes

Missing GROUP BY

A plain column in SELECT needs GROUP BY. SELECT B, SUM(F) PIVOT C without GROUP BY returns an error. Add GROUP BY B: the GROUP BY column provides the row labels for the pivot. Without a plain column, SELECT SUM(F) PIVOT C works with no GROUP BY and returns one row of totals.

Trying to use LABEL with PIVOT headers

LABEL cannot rename the auto-generated PIVOT column headers. PIVOT creates headers from the unique values in the pivot column (like “Baker Street sum Revenue”). To rename them, add a header row manually above the QUERY output.

Putting PIVOT before GROUP BY

Clause order is fixed: SELECT, WHERE, GROUP BY, PIVOT, ORDER BY, LIMIT. PIVOT must come after GROUP BY.

Tips

1. PIVOT columns are sorted, not kept in data order. The regions become columns in alphabetical order, Baker Street, Scotland Yard, Whitehall, no matter which one appears first in the data. ORDER BY sorts the rows, not these columns.

2. Blank cells in the pivot result mean no matching data exists. Sherlock Holmes has no Whitehall transactions, so that cell is empty. A blank is not an error, so IFERROR will not turn it into a zero.

3. PIVOT works on any column with a manageable number of unique values. A column with 3 regions creates 3 extra columns. A column with 100 products creates 100 columns. Keep the pivot column to a reasonable number of categories.

Note

PIVOT and GROUP BY can use different columns. GROUP BY defines the rows, PIVOT defines the columns. The aggregate function fills the intersection of each row and column.

Frequently Asked Questions

What does PIVOT do in QUERY in Google Sheets?
PIVOT rotates unique values from one column into new column headers. Combined with an aggregate function like SUM or COUNT, it creates a cross-tabulated summary where rows represent one dimension and columns represent another.
What is the difference between QUERY PIVOT and a pivot table?
QUERY PIVOT is a formula that returns a live, cross-tabulated result directly in your sheet. A pivot table is a separate interactive object with its own editor. QUERY PIVOT updates automatically when source data changes and can be combined with WHERE and ORDER BY in the same formula.
Can you use PIVOT with multiple aggregate functions?
Yes. SELECT B, SUM(F), COUNT(F) GROUP BY B PIVOT C works. Each region gets one column per aggregate, with headers like Baker Street sum Revenue.
How do you rename PIVOT column headers in QUERY?
PIVOT auto-generates headers from the pivot column values (like Baker Street, Scotland Yard, Whitehall). You cannot use LABEL to rename PIVOT headers directly. To rename them, wrap the QUERY in a second formula or manually adjust the headers.
Can you combine QUERY PIVOT with WHERE?
Yes. WHERE filters the data before PIVOT creates the cross-tabulation. For example: SELECT B, SUM(F) WHERE F > 200 GROUP BY B PIVOT C returns only transactions with revenue over $200, then pivots by region.

You read about QUERY. Now type it.

Unit 1 of the course is free: 6 short lessons in a grid that checks every formula. They teach the Google Sheets skills you'll actually use.

Start the course free

First 6 lessons free. No card needed. See plans

Keep going

Continue learning

Unit 2 is next. Get full access

Practice this in the app

Practice QUERY

Spot an error on this page? Tell us.

First 6 lessons free. No credit card required.

Start the course free
Continue learning

Cookie policy · Privacy policy