Google Sheets Group By: QUERY, Pivot Tables and Row Groups

Google Sheets lets you group data three ways: the QUERY function with a GROUP BY clause, a pivot table built from the Insert menu, or row and column groups that collapse rows visually. QUERY suits formula-driven outputs, pivot tables suit quick summaries, and row groups hide detail without touching your data.

  • QUERY GROUP BY aggregates data with SUM, COUNT, AVG and more, exactly like SQL.
  • Pivot tables in Google Sheets update automatically when source data changes and need zero formula knowledge to set up.
  • Row groups are purely visual: they collapse rows for cleaner printing or presentation without affecting calculations.
  • You can group by month using TEXT(date,"YYYY-MM") inside a QUERY or as a pivot row field.
  • The google sheets group by skill is one of the most tested topics in data analyst interview questions, so practising all three methods pays off fast.

Google Sheets Group By Methods: When to Use Each

Google Sheets gives you three distinct tools for grouping data, and picking the wrong one wastes time. Each serves a different use case, so it is worth knowing exactly when to reach for each one.

Think of it this way: QUERY is for analysts who want formula-driven, repeatable outputs. Pivot tables are for business users who need quick summaries without writing a single function. Row groups are for anyone who wants a cleaner view of a large sheet without destroying the underlying structure.

Comparison of All Three Methods

Method Best For Updates Automatically Needs Formula Knowledge
QUERY GROUP BY Repeatable, formula-driven aggregations Yes Yes
Pivot Table Quick drag-and-drop summaries Yes No
Row / Column Groups Visual collapsing for cleaner views N/A No

According to McKinsey’s 2023 State of Data and Analytics report, organisations that embed spreadsheet-based aggregation workflows into their reporting cycles reduce manual data preparation time by up to 40%. If you are building skills for a data role, mastering both QUERY and pivot tables is non-negotiable. The difference between a data analyst and a data scientist often comes down to how comfortable each is with tools like these versus full programming environments.

QUERY with GROUP BY in Google Sheets

The QUERY function runs a SQL-like query directly on a range in your spreadsheet. It is one of the most powerful functions in Sheets and almost nobody uses it to its full potential.

The basic syntax is: =QUERY(data, “SELECT col, AGG(col) GROUP BY col”, headers). The first argument is your data range, the second is your SQL-style query string in quotes, and the third tells Sheets how many header rows your data has.

A Practical Example

Say you have sales data in columns A (Region), B (Salesperson) and C (Revenue). To get total revenue by region, write:

=QUERY(A:C, “SELECT A, SUM(C) GROUP BY A”, 1)

Sheets returns a clean two-column table: Region and total revenue. Change the source data and the output updates instantly. No copy-paste, no manual totals.

Google Sheets Group By Multiple Columns

You can group by more than one column by listing each column in both the SELECT and GROUP BY clauses. To break revenue down by region and salesperson simultaneously:

=QUERY(A:C, “SELECT A, B, SUM(C) GROUP BY A, B”, 1)

Sheets returns one row per unique region-salesperson combination. This is the google sheets group by multiple columns pattern used in most real reporting workflows.

Google Sheets Query Group By Count

To count records rather than sum values, swap SUM for COUNT:

=QUERY(A:C, “SELECT A, COUNT(B) GROUP BY A”, 1)

This returns the number of transactions per region. COUNT, AVG, MAX and MIN all follow the same pattern inside the query string.

Grouping by Month with QUERY

Date grouping trips up a lot of beginners. If column A holds dates, you cannot GROUP BY A directly and get monthly totals. You need to extract the month first using a helper column.

Add a helper column D with =TEXT(A2,”YYYY-MM”) and drag it down. Then run:

=QUERY({D2:D,C2:C}, “SELECT Col1, SUM(Col2) GROUP BY Col1 ORDER BY Col1”, 0)

You will get monthly totals sorted chronologically. This is exactly the kind of technique that separates people who know Sheets from people who really know Sheets.

Common QUERY Mistakes

  • Forgetting to match column letters in the query string to your actual sheet columns. QUERY uses the column letter from the selected range, not the sheet. If your range starts at column C, that column is Col1 in array syntax.
  • Mixing data types in a column. QUERY silently drops rows where the column has mixed text and numbers. Always clean your data first.
  • Leaving the headers argument blank. It defaults to -1, which means Sheets guesses, and it guesses wrong a significant portion of the time.

If you have worked with Pandas and NumPy in Python, QUERY GROUP BY will feel instantly familiar. It is the same groupby-aggregate pattern, just inside a spreadsheet cell.

Pivot Tables in Google Sheets

Pivot tables are the fastest way to do a google sheets group by without writing any formula. Go to Insert > Pivot table, choose your data range and destination sheet, and Sheets opens a side panel where you drag fields into Rows, Columns, Values and Filters.

To group sales by region and month, drag Region into Rows, drag the date column into Rows again (Sheets will offer to group by month, quarter or year automatically), and drag Revenue into Values with SUM as the aggregation. The whole thing takes under two minutes.

Pivot Table Tips That Save You Time

One thing most people miss: you can add a calculated field to a pivot table. Click “Add” next to Values, scroll down to “Calculated field”, and write a custom formula like Revenue / Units to get average price per unit directly in the pivot. No helper column needed.

Pivot tables also support filtering. Add a column to the Filters section and a dropdown appears at the top of your pivot output. This is how finance teams at Indian companies like Infosys or Wipro typically build monthly MIS reports without touching a single formula. A Bengaluru-based HR analyst, for example, might use a pivot table to group monthly hiring data pulled from a Google Form by department and location, giving leadership a one-click summary without any formula maintenance.

Pivot Table vs QUERY: Which One Is Right

Use a pivot table when your audience needs to interact with the data or when you are doing exploratory analysis and do not know exactly what you want yet. Use QUERY when the output needs to feed into another formula, or when you want the grouping logic documented in a cell someone can read and audit later.

For data analytics projects you are building for a portfolio, QUERY shows more technical depth. A pivot table is fine for internal reporting, but a recruiter reviewing your work will be more impressed by a well-written QUERY formula.

Grouping Rows and Columns in Google Sheets

Row groups are the simplest google sheets group by feature and the most underused. Select the rows you want to collapse, right-click, and choose View more row actions > Group rows. A small minus button appears on the left margin. Click it to collapse, click the plus to expand.

This is purely visual. The data is still there, formulas still reference it, and nothing changes in your calculations. It is ideal for monthly detail rows under a quarterly summary, or for hiding raw data rows that feed a dashboard.

Column Groups Work the Same Way

Select columns, right-click, choose Group columns. The toggle appears at the top of the sheet. Teams building large financial models use this constantly to hide input assumption columns without protecting or deleting them.

One practical tip: if you are sharing a sheet with a manager or client, row groups let you present a clean summary view while keeping all the detail one click away. You do not need to create a separate summary tab, which means you are not maintaining two copies of the same data.

Data skills like these are in real demand. According to NASSCOM’s 2024 Future of Work report, data and analytics roles in India are projected to grow at over 30% annually through 2026, with spreadsheet proficiency listed as a baseline requirement for entry-level analyst positions. If you are building toward a career in data, check out what the highest paying tech skills in 2026 look like and where spreadsheet work fits in.

LinkedIn’s 2024 Jobs on the Rise report for India listed data analyst as a top-five fastest-growing role, with SQL and spreadsheet skills appearing in over 65% of job descriptions for the category. The google sheets group by techniques on this page map directly to those requirements.

Frequently Asked Questions

How do I group by in Google Sheets?

You can group data in Google Sheets three ways: use the QUERY function with a GROUP BY clause for formula-driven aggregation, use a pivot table from the Insert menu for drag-and-drop summaries, or use row groups to visually collapse rows. All three methods work on live data and update when the source changes. QUERY is the most flexible for repeatable, auditable outputs.

How does QUERY GROUP BY work?

The QUERY function accepts a SQL-style query string as its second argument. Writing =QUERY(A:C,”SELECT A, SUM(C) GROUP BY A”,1) tells Sheets to group all rows by the value in column A and return the sum of column C for each group. Any standard SQL aggregate, including COUNT, AVG, MAX and MIN, works the same way inside the query string.

Can I group rows in Google Sheets?

Yes. Select the rows you want to group, right-click, and choose View more row actions, then Group rows. A toggle button appears on the left margin of the sheet, letting you collapse or expand the group with one click. The data stays intact and all formulas that reference those rows continue to work normally.

Is there a pivot table in Google Sheets?

Yes, Google Sheets has a full pivot table feature. Go to Insert, then Pivot table, select your data range, and use the side panel to drag fields into Rows, Columns, Values and Filters. Sheets also suggests pivot configurations automatically based on your data. Pivot tables update in real time when source data changes, with no manual refresh needed.

How do I group by month in Google Sheets?

In a pivot table, add your date column to the Rows section and Sheets will offer to group by day, month, quarter or year automatically. In QUERY, add a helper column with =TEXT(A2,”YYYY-MM”) and group by that column instead of the raw date. Both methods produce clean monthly totals that sort chronologically.

How do I group by multiple columns in Google Sheets?

In QUERY, list each column in both the SELECT and GROUP BY clauses: =QUERY(A:C, “SELECT A, B, SUM(C) GROUP BY A, B”, 1). In a pivot table, drag multiple fields into the Rows section. Sheets stacks them as nested row groupings automatically.

The core idea behind google sheets group by is simple: pick the tool that matches how you will use the output. QUERY for formulas that feed other calculations, pivot tables for fast interactive summaries, and row groups for a cleaner view without touching the data. Start with one real dataset this week, build the same summary all three ways, and you will know instinctively which to reach for in any situation.

  1. Take a CSV from any public dataset (try data.gov.in) and load it into Google Sheets. Write a QUERY GROUP BY formula to count records by category using the google sheets query group by count pattern above.
  2. Build a pivot table from the same data, grouping a date column by month. Compare the output to your QUERY result.
  3. Use row groups to collapse the detail rows and share the sheet with a peer for feedback on readability.

If you find this kind of analytical thinking interesting, it transfers directly into security work. SOC analysts filter log data, build detection dashboards and spot anomalies in large datasets every single day, and the grouping logic you just learned is exactly what that looks like in practice. Explore the EC-Council Certified SOC Analyst course at 3.0 University to see how data skills feed into a cybersecurity career, or browse the full 3.0 University course catalogue covering AI, Blockchain, Ethical Hacking and more. For students still weighing their options, the best free online learning platforms for students in 2025 is a good place to start building your skills before committing to a certification.

Last updated: June 2025. Reviewed by the 3University editorial team.

We create, review, and maintain educational content covering Cybersecurity, Ethical Hacking, Artificial Intelligence, Blockchain, Web3, and emerging technologies.

Read More Articles