Sub topic 9
Sorting and filtering table data
This chapter assumes you can convert a range to a table, that you know the table's header row and column types, and that you can write basic formulas such as SUM. Here you will learn how to sort and filter a table, what those actions do to the rest of your sheet, and the mistakes that usually go wrong.
The examples use the Orders table from earlier chapters:
Order ID | Customer | Order Date | Amount | Paid
1001 | Acme | 2026-01-05 | 250 | TRUE
1002 | Globex | 2026-01-09 | 480 | FALSE
1003 | Initech | 2026-01-12 | 125 | TRUEWhere the controls live
A table puts a small filter control in each header cell. Hover over a header and a dropdown arrow appears. Its menu has sort commands and filter options for that column only. You do not need to select a range first or turn a filter on. The table already knows its own boundaries.
This is the main difference from a plain range. On a plain range, you either select the cells and sort them, or you create a filter that covers a range you choose. If you select the wrong cells, the sort can split rows apart. A table removes that risk because it treats each row as one record.
Sorting a table
Open the dropdown on a column header and choose one of the sort commands. The two basic choices are:
- Sort A to Z, which sorts ascending. For numbers this means smallest first, and for dates it means oldest first.
- Sort Z to A, which sorts descending. For numbers this means largest first, and for dates it means newest first.
The whole row moves together. If you sort Orders by Amount, the Customer, Order Date, and Paid values follow their Order ID. Nothing outside the table moves. A note in cell H2 beside the table stays where it is, even though the table's rows around it are rearranged.
How column types affect the order
Sorting depends on the column type, so the type you set earlier now matters.
| Column type | Ascending order | Common problem |
|---|---|---|
| Number | 2, 10, 100 | Numbers stored as text sort as 10, 100, 2 |
| Date | Oldest to newest | Text that looks like a date sorts alphabetically |
| Text | A to Z | Uppercase and lowercase letters are treated alike |
| Checkbox | Unchecked, then checked | Blank cells and `FALSE` look the same |
| Dropdown | By the text of the chosen item | The order is alphabetical, not the order of the list |
If a Number column sorts as 10, 100, 2, the cells hold text. Fix the data, not the sort. Reapply the Number column type and check that the values are right-aligned, which is how Sheets shows true numbers by default.
Sorting by more than one column
The header dropdown sorts by one column at a time. To sort by Customer and then by Amount within each customer, sort in reverse order of priority. Sort by Amount first, then sort by Customer. This works only if the second sort keeps ties in their existing order, and Sheets does not promise that for every sort method. If you need a guaranteed multi-level order, put it in a formula instead of relying on the table's sort. This formula returns a sorted copy in another location:
=SORT(Orders, 2, TRUE, 4, FALSE)The arguments mean: sort by column 2 (Customer) ascending, then by column 4 (Amount) descending. The original table stays unchanged, and the copy updates when the table does.
Filtering a table
Open the dropdown on a column header and choose the filter option. You can filter in two ways:
- Filter by values. A list of every distinct value in the column appears with a checkbox next to each one. Clear the boxes for values you want to hide.
- Filter by condition. You pick a rule, such as "Greater than", "Date is before", or "Text contains", and give a value.
Filtering hides rows. It does not delete them. Hidden rows keep their data, and removing the filter brings them back.
Combining filters
Filters on different columns combine with AND. If you filter Paid to FALSE and Amount to "Greater than 200", you see only unpaid orders over 200. A row must pass every active filter to stay visible.
Inside one column, the "filter by values" list works as OR. If you leave Acme and Globex checked in the Customer column, you see rows for either customer.
Filters and formulas
Filtering and formulas interact in a way that surprises many people. Most standard functions ignore the filter. Both of these formulas return the total for all rows, hidden or not:
=SUM(Orders[Amount])
=COUNTIF(Orders[Paid], TRUE)If you want a total of only the visible rows, use SUBTOTAL. Function code 109 sums the values and skips rows hidden by a filter:
=SUBTOTAL(109, Orders[Amount])A similar formula, =SUBTOTAL(103, Orders[Order ID]), counts the visible non-empty cells. Use these in a summary cell outside the table so you can watch the figures change as you adjust filters.
Filters, sorting, and other people
Sorting changes the stored order of rows. Everyone who opens the file sees the new order. That means a sort is a real edit, and it appears in the version history.
Filters can behave differently, and you should check how your version of Sheets handles them. A filter you apply may be visible to every collaborator who opens the file, so a colleague might think data is missing when a filter is hiding it. Before you share a sheet, clear your filters or tell people that filters are active. A filtered column header shows a visual cue, so look at the header row when numbers look wrong.
The following diagram summarizes what happens when you use a header dropdown.
Interaction with growth
Tables expand when you add a row below them, as described in the previous chapter on automatic expansion. Sorting and filtering follow that growth. A new row becomes part of the sort and filter scope as soon as the table includes it.
Be careful with a new row you add while a filter is active. If the new row does not meet the filter condition, it may disappear from view immediately after you enter it. The row exists, but the filter hides it. Clear the filter to find it again.
Similarly, a sort does not re-run on its own. If you sort by Amount and then add a row with a small value, the row stays at the bottom. Sort again to place it correctly.
Common problems
- Rows seem to be missing. Check each header for a filter indicator. A forgotten filter on a column you are not looking at is the most common cause.
- A sort puts blanks in the wrong place. Blank cells go to the end in both ascending and descending sorts. Fill the blanks or filter them out.
- Dates sort in the wrong order. The column holds text. Convert the values to real dates and set the Date column type.
- A formula outside the table shows the wrong total after sorting. Formulas that use a fixed range such as
=SUM(C2:C4)can point to different cells in a sorted sheet. Use a structured reference such asOrders[Amount]so the formula follows the column. - A sort will not apply. Look for merged cells or a protected range inside the table area. Remove the merge or ask the sheet owner to adjust the protection.
A worked example
You want the three largest unpaid orders for a follow-up list.
- Open the Paid header dropdown and filter by values. Clear
TRUEso onlyFALSErows remain. - Open the Amount header dropdown and choose Sort Z to A. The largest unpaid orders are now at the top.
- In a cell outside the table, enter
=SUBTOTAL(109, Orders[Amount])to see the total value of the visible unpaid orders. - When you finish, clear the Paid filter so that the next person sees all rows.
For the sample data, only order 1002 is unpaid, so one row remains and the subtotal is 480. With a larger table you would read the first three rows.
If you want a list that stays current without touching the table's view, use a formula in another area:
=QUERY(Orders, "select A, B, D where E = FALSE order by D desc limit 3", 1)The formula leaves the table's own sort and filter state alone. That makes it better for a report that several people read.
Choosing between a view change and a formula
| Goal | Better tool |
|---|---|
| Look at the data in a different order for a moment | Header dropdown sort |
| Check a subset quickly | Header dropdown filter |
| Total only visible rows | `SUBTOTAL` |
| Produce a stable report from the table | `SORT`, `FILTER`, or `QUERY` in another area |
| Guarantee a multi-column order | `SORT` with several keys |
Exercise
A table named Orders has an Amount column. You filter the Paid column to show only FALSE rows. The cell =SUM(Orders[Amount]) still shows the total of all orders. What formula shows the total of only the visible rows, and why did the first formula not change?
Show answer
Use =SUBTOTAL(109, Orders[Amount]). SUM includes every row in the column, whether a filter hides it or not. SUBTOTAL with function code 109 sums only the rows that are visible.
Exercise
You sort the Orders table by Amount, then add a new row with a very small amount at the bottom. Where does the new row appear, and what should you do to put it in the right place?
Show answer
The new row stays at the bottom, because a sort does not re-run when the table grows. Sort the Amount column again to place the row in the correct position.