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 (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.
Sheets Bootcamp
March 10, 2026 · Updated November 5, 2026
Table of Contents
Quick Answer
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
- How to Create a QUERY PIVOT: Step-by-Step
- PIVOT with COUNT
- PIVOT with AVG
- PIVOT with WHERE (Filter Before Pivoting)
- QUERY PIVOT vs Pivot Tables
- Common Mistakes
- Tips
- Related Google Sheets Tutorials
- FAQ
PIVOT Syntax
PIVOT goes after GROUP BY in the query string:
=QUERY(data, "SELECT groupColumn, AGGREGATE(valueColumn) GROUP BY groupColumn PIVOT pivotColumn") | Part | Role | Example |
|---|---|---|
groupColumn | Becomes the row labels | B (Salesperson) |
AGGREGATE(valueColumn) | The calculation in each cell | SUM(F) (total Revenue) |
pivotColumn | Unique values become column headers | C (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.
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
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Date | Salesperson | Region | Product | Units | Revenue | Commission |
| 2 | 1/5/2026 | Sherlock Holmes | Baker Street | Listening Device | 12 | $239.88 | $24.00 |
| 3 | 1/7/2026 | Irene Adler | Scotland Yard | Forensic Chemistry Set | 8 | $360.00 | $36.00 |
| 4 | 1/8/2026 | Inspector Lestrade | Baker Street | Pocket Watch | 15 | $525.00 | $52.50 |
| 5 | 1/10/2026 | Sherlock Holmes | Baker Street | Field Binoculars | 5 | $325.00 | $32.50 |
| 6 | 1/12/2026 | Mycroft Holmes | Scotland Yard | Cipher Decoder | 20 | $570.00 | $57.00 |
| 7 | 1/14/2026 | Irene Adler | Whitehall | Magnifying Glass | 25 | $624.75 | $62.50 |
| 8 | 1/15/2026 | Inspector Lestrade | Scotland Yard | Listening Device | 10 | $199.90 | $20.00 |
| 9 | 1/18/2026 | Sherlock Holmes | Baker Street | Disguise Kit | 3 | $269.97 | $27.00 |
| 10 | 1/20/2026 | Mycroft Holmes | Whitehall | Brass Telescope | 8 | $336.00 | $33.60 |
| 11 | 1/22/2026 | Irene Adler | Scotland Yard | Lockpick Set | 6 | $330.00 | $33.00 |

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.
Create a basic PIVOT
Select an empty cell and enter:
=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.

Add WHERE to filter before pivoting
Enter:
=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.

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:
=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.

PIVOT with AVG
AVG calculates the average value per cell:
=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:
| Feature | QUERY PIVOT | Pivot Table |
|---|---|---|
| Output location | In the same sheet as a formula | Separate sheet or overlay |
| Auto-updates | Yes, on data change | Yes, on refresh |
| Combines with filters | WHERE in same formula | Separate filter controls |
| Multiple aggregates | Yes, each gets its own columns | Multiple in one pivot |
| Custom formulas | Full QUERY syntax | Limited calculated fields |
| Learning curve | Text-based query string | Point-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.
Related Google Sheets Tutorials
- QUERY Function: Complete Guide: covers all QUERY clauses with syntax and examples
- QUERY GROUP BY: aggregate data without cross-tabulation
- QUERY ORDER BY: sort QUERY results ascending or descending
- Pivot Tables Guide: interactive pivot tables for point-and-click analysis
Frequently Asked Questions
What does PIVOT do in QUERY in Google Sheets?
What is the difference between QUERY PIVOT and a pivot table?
Can you use PIVOT with multiple aggregate functions?
How do you rename PIVOT column headers in QUERY?
Can you combine QUERY PIVOT with WHERE?
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 freeFirst 6 lessons free. No card needed. See plans
Practice this in the app
Practice QUERYSpot an error on this page? Tell us.
Thanks. We'll fix it and update the page.