Sub topic 1
Prepare your data: one table, one header row
Sorting and filtering tools in Google Sheets guess where your data starts and ends. If the layout is clean, the guesses are right. If it isn't, you get header rows sorted into the data, filters that cover only part of a table, and formulas that return the wrong rows. This chapter covers the layout rules that make every later chapter behave predictably.
Prerequisites
This chapter assumes you can already do the following:
- Navigate a spreadsheet: cells, rows, columns and tabs.
- Enter data and simple formulas such as
=SUM(A1:A10). - Read cell ranges such as
A2:D100.
You don't need any sorting or filtering experience.
What a "table" means in Sheets
Google Sheets has no strict table object in the way a database does. A table here is a convention: a rectangular block of cells where the following are true.
- The first row holds column labels (the header row).
- Each row below it is one record, such as one sale, one customer or one task.
- Each column holds one kind of value, such as a region name, a date or an amount.
Sorting, filtering and the functions SORT, FILTER and QUERY all rely on this shape. They don't read your intent. They look at the cells around your selection and infer the block.
Here is a well-formed table in A1:D6:
| Region | Rep | Amount | Date |
|---|---|---|---|
| West | Ana | 1200 | 2026-01-05 |
| East | Ben | 850 | 2026-01-07 |
| West | Cho | 2300 | 2026-01-12 |
| North | Dev | 400 | 2026-01-15 |
| East | Eli | 1500 | 2026-01-20 |
The later chapters use this same shape, with the data starting in row 2 and spanning columns A to D.
Rule 1: Use exactly one header row
A header row is a single row of labels directly above the data. Keep these points in mind.
- One row only. Don't stack a title row, a subtitle row and then the labels. Sheets treats the row you select as the header, and any extra rows end up sorted into the data.
- Unique, non-empty labels. Write
Region, not a blank cell. Two columns both calledAmountmakeQUERYand filter menus harder to read. A blank header cell can stop Sheets from recognizing the column as part of the table. - Short, plain text. Avoid line breaks inside a label. Avoid labels that are numbers or dates, because Sheets may mistake them for data.
- No merged cells. A merged header such as "Q1 Results" spanning three columns breaks sorting. Sheets can't sort a range that contains merged cells in some positions, and it rejects the operation with an error.
If you want a title above the table, put it on a separate tab, or leave at least one fully blank row between the title and the header. A blank row separates the title from the table and keeps the table's edges clear. Even then, remember that a blank row is what ends a table, so never put one inside it (see Rule 3).
Rule 2: One kind of value per column
Each column should hold one data type. A column called Amount should contain only numbers. A column called Date should contain only real dates.
This matters because Sheets sorts by type first. Numbers, text and blanks are ordered as separate groups, not mixed together by appearance. A single cell holding the text "1,200 USD" in an otherwise numeric column ends up in the wrong place and may be silently skipped by sums.
Some things to avoid inside a column:
- Units typed into numbers, such as
1200 USD. Put the unit in the header (Amount (USD)) and keep the cells numeric. - Notes in value cells, such as
pending, in a numeric column. Add aStatuscolumn instead. - Mixed casing and spacing in categories:
West,westandWest(with a trailing space) are three different values to a filter. Settle on one spelling.
You can check a column quickly with a formula. This counts the cells in C2:C that are filled in but aren't real numbers:
=COUNTA(C2:C)-COUNT(C2:C)COUNTA counts all non-empty cells and COUNT counts only numbers. If the result is greater than 0, some entries are text, such as numbers stored as text. A later chapter in this tutorial covers how to repair these.
Rule 3: No blank rows or blank columns inside the table
When you select one cell and use a feature, Sheets expands to the surrounding block of filled cells. That block stops at the first completely blank row or column. If you leave a blank row in the middle of your data, a sort or filter may cover only the rows above it. The remaining rows then stay where they were, and your table is quietly split in two.
Blank cells are fine as long as the row or column isn't completely empty. A missing Date for one record is acceptable. A completely empty row is the problem.
Rule 4: Keep totals, notes and other tables out of the data block
Anything that isn't a record shouldn't sit inside or directly against the table.
- Totals rows. A
Totalrow at the bottom of the table sorts up into the middle of your data. Put totals above the table on a separate area, on another tab, or calculate them with a formula that reads the data range. - Notes under the table. A comment in
A8directly below the data may be included when Sheets expands the selection. - Side-by-side tables. If a second table starts in column F with no gap, a sort of the first may run into it. Leave at least one fully empty column between tables, or better, put each table on its own tab.
Rule 5: Prefer a long layout to a wide one
Suppose you track monthly sales. You could add one column per month (Jan, Feb, Mar, and so on), which is a wide layout. Or you could keep one Month column and one Amount column, with one row for each region and month, which is a long layout.
| Region | Month | Amount |
|---|---|---|
| West | Jan | 1200 |
| West | Feb | 1350 |
| East | Jan | 850 |
| East | Feb | 900 |
The long layout is easier to filter (Month = Jan), easier to sort (by Amount), and doesn't need a new column every month. Wide layouts are fine for a final report that people read, but they make poor source data. If you need both, keep the long table as the source and build the wide report from it.
Freeze the header row
Once the table has a clean header, freeze it so it stays visible while you scroll. Choose View > Freeze > 1 row. Freezing doesn't change how sorting works, but it makes the header row obvious to every collaborator. Some Sheets features also use a frozen row as a hint that the first row is a header, so freezing helps the Data menu's sort options handle the header correctly.
A pre-flight checklist
Before you sort or filter any dataset, run through this sequence.
Why open-ended ranges help
When a table grows, a fixed range such as A2:D100 stops covering new rows. Writing the range with no end row, such as A2:D, covers every row to the bottom of the sheet, including rows you add later. The formulas in this tutorial use this form for that reason.
An open-ended range only works well if nothing else sits below the table in those columns. That is one more reason to keep notes and totals out of the data block.
=COUNTA(A2:A)This returns the number of filled records in column A. If you see a number larger than you expect, something below the table is being counted.
Common mistakes
| Symptom | Likely cause | Fix |
|---|---|---|
| The header row jumps into the middle of sorted data | Sort was applied without telling Sheets the first row is a header | Freeze the row or select the header option, then sort again |
| Only part of the table is sorted | A completely blank row inside the data | Delete the blank row |
| Sort is refused with a merged-cell error | Merged cells in the range | Unmerge them |
| A `Total` row appears in the middle of results | Totals stored inside the data block | Move totals out of the table |
| Filter menu shows `West` and `West ` separately | Trailing space or inconsistent spelling | Standardize the text |
Exercise
A teammate's sheet has a title in A1, labels in A2:D2, data from A3 down, and a Total row in the last data row. Name three changes that prepare it for sorting and filtering.
Show answer
Move the title off the table, either to another tab or above a fully blank separator row, so the labels sit in a single header row. Remove or relocate the Total row so it can't be sorted into the data, for example by calculating it with a formula that reads the data range. Check that no fully blank row or merged cell sits inside A:D, then freeze the header row.
Exercise
Column C (Amount) in C2:C contains 40 filled cells. =COUNT(C2:C) returns 37. What does that tell you, and what would you do next?
Show answer
Three cells are not real numbers, probably text such as "1,200 USD" or numbers stored as text. =COUNTA(C2:C)-COUNT(C2:C) would return 3. Find those cells, remove stray text or units, and convert them to true numbers before sorting.