Excel does not have a single "group by" function like a database does, but it offers several ways to organize and summarize data by category

If you are coming from a database or a tool like SQL, you might expect a "group by" command in Excel. Excel does not work that way. Instead, you organize data by category using sorting, subtotals, pivot tables, or formulas. Which method you choose depends on whether you want to reorganize your existing data, create a summary in a new location, or leave the original data untouched.

The fastest route for most people is a pivot table — it groups data, counts or sums by category, and updates if your source data changes. If you need to keep your original data in place and add subtotals between groups, use the Subtotals feature. If you want to write a formula that sums or counts by category without moving anything, use SUMIF or COUNTIF.

Key Takeaways

  • A pivot table is the quickest way to group data and see totals by category without changing your original spreadsheet.
  • The Subtotals feature reorganizes your data by adding summary rows between groups, and works only if your data is already sorted by the grouping column.
  • SUMIF and COUNTIF formulas let you sum or count by category in a new location without moving your original data.
  • Sorting your data by the column you want to group by is the first step for Subtotals and makes manual grouping easier to read.

Using a Pivot Table to Group and Summarize

A pivot table is the most powerful way to group data in Excel. It reads your source data, groups it by the column you choose, and calculates totals or counts automatically. The original data stays unchanged, and you can rearrange the pivot table or change what it summarizes without touching the source.

To create a pivot table, select your data (including headers) and go to the Insert tab, then click Pivot Table. Excel opens a dialog asking where you want the pivot table to appear — choose a new sheet or a blank area of the current sheet. Click OK. A new window appears with your column names listed on the right. Drag the column you want to group by into the Rows box, and drag the column you want to sum or count into the Values box. Excel automatically sums numeric columns or counts text columns. The pivot table appears instantly.

If your data changes, right-click the pivot table and select Refresh to update it. If you want to change what the pivot table shows, drag columns between the Rows, Columns, Filters, and Values boxes on the right side of the screen.

Adding Subtotals to Reorganize Data by Group

The Subtotals feature works differently from a pivot table — it reorganizes your actual data by inserting summary rows between groups. This is useful if you want to keep your data in one place and see subtotals for each group without creating a separate summary sheet.

First, sort your data by the column you want to group by. Select all your data including headers. Go to the Data tab and click Subtotals. A dialog opens with three choices: which column to group by, what function to use (Sum, Count, Average, etc.), and which columns to calculate on. Choose your settings and click OK. Excel inserts subtotal rows after each group and a grand total at the bottom. You can click the numbered outline buttons on the left (1, 2, 3) to collapse or expand the groups.

If you add or remove rows later, you can run Subtotals again — Excel will remove the old subtotals and add new ones. To remove subtotals entirely, go back to Data > Subtotals and click Remove All.

Writing Formulas to Sum or Count by Category

If you want to create a summary in a separate location without moving your original data, use SUMIF to sum values that match a category, or COUNTIF to count them. These formulas work anywhere in your spreadsheet and do not reorganize anything.

The SUMIF formula takes three parts: the range to check, the category to match, and the range to sum. For example, if your data is in columns A through C with product names in column A and sales in column C, the formula =SUMIF(A:A,"Apples",C:C) sums all sales where the product is Apples. You can also reference a cell instead of typing the category directly: =SUMIF(A:A,E2,C:C) sums sales for whatever product name is in cell E2.

COUNTIF works the same way but counts instead of summing. =COUNTIF(A:A,"Apples") counts how many rows have Apples in column A. You can use wildcards too: =COUNTIF(A:A,"Apple*") counts anything starting with "Apple".

Sorting Data Before Grouping

Sorting is not grouping, but it is the foundation for the Subtotals feature and makes manual grouping much easier to read. To sort by a column, select all your data including headers, go to the Data tab, and click Sort. Choose the column to sort by and whether you want ascending (A to Z) or descending (Z to A) order. Click OK.

If you sort by the same column you plan to group by, the Subtotals feature will work correctly. Sorting also makes it easier to see all rows in the same category together, which is helpful if you want to manually review or edit grouped data.

Choosing Between Pivot Tables, Subtotals, and Formulas

Use a pivot table if you want a summary that updates automatically and does not change your original data. Pivot tables are best for exploring data quickly and trying different groupings without affecting the source.

Use Subtotals if you want to reorganize your data in place and see subtotals between groups. This works well for reports where you want the grouped data and the subtotals in the same sheet, and you do not mind the data being rearranged.

Use SUMIF or COUNTIF formulas if you want to build a custom summary in a separate location, or if you need more control over the layout and formatting. Formulas are also the right choice if you want to reference the summary in other calculations.

Frequently Asked Questions

Can I group by more than one column at once?

Yes. In a pivot table, drag multiple columns into the Rows box — Excel will group by the first column, then by the second within each group. With Subtotals, you can run the feature once, then run it again on a different column with the "Replace existing subtotals" option unchecked. With formulas, you would need to write a more complex formula or use a helper column to combine the grouping columns.

What if my data has blank cells in the grouping column?

Pivot tables and Subtotals will treat blanks as a separate group. If you have many blanks, fill them in or filter them out before grouping. Formulas like SUMIF will ignore blank cells in the criteria range, so they handle blanks more gracefully.

Can I change what a pivot table calculates after I create it?

Yes. Right-click any number in the pivot table and select Summarize Values By to change from Sum to Average, Count, or another function. You can also drag columns between the Rows, Columns, Filters, and Values boxes on the right side to rearrange what the pivot table shows.

Does grouping change my original data?

Pivot tables and formulas do not change your original data — they create a summary elsewhere. Subtotals reorganizes your data by inserting rows, so it does change the layout of your original sheet. You can undo it or click Remove All in the Subtotals dialog to restore the original order.

Can I group by date ranges instead of exact dates?

Pivot tables have a built-in feature for this — right-click a date in the pivot table and select Group to choose whether to group by month, quarter, year, or a custom range. With Subtotals or formulas, you would need to create a helper column that converts dates into the range you want (for example, "Q1 2024"), then group or sum by that column instead.