Working with Data
You've got the formulas. Now learn to manage the data itself: sorting it, filtering it, locking headers in place, controlling what users can enter, and giving ranges memorable names.
You'll need a 20 row sales dataset for this module. You can type it in yourself or use the one below, it covers all the exercises. Open a new Google Sheet and enter it starting at cell A1.
| A: Date | B: Salesperson | C: Category | D: Product | E: Units | F: Revenue |
|---|---|---|---|---|---|
| 2024-01-05 | Alice | Electronics | Laptop | 2 | 2400 |
| 2024-01-08 | Bob | Books | Python Guide | 10 | 350 |
| 2024-01-12 | Alice | Clothing | Jacket | 5 | 445 |
| 2024-01-15 | Carol | Electronics | Tablet | 3 | 1350 |
| 2024-01-20 | Bob | Electronics | Headphones | 8 | 960 |
| 2024-02-03 | Carol | Books | Stats Textbook | 12 | 540 |
| 2024-02-07 | Alice | Electronics | Keyboard | 15 | 750 |
| 2024-02-14 | David | Clothing | Sneakers | 6 | 660 |
| 2024-02-18 | Bob | Books | Data Viz Book | 7 | 245 |
| 2024-02-25 | Carol | Electronics | Monitor | 1 | 450 |
| 2024-03-01 | David | Electronics | Webcam | 10 | 790 |
| 2024-03-05 | Alice | Clothing | T shirt Pack | 20 | 400 |
| 2024-03-10 | Bob | Electronics | USB Hub | 25 | 388 |
| 2024-03-15 | Carol | Clothing | Scarf | 30 | 270 |
| 2024-03-20 | David | Books | SQL Guide | 8 | 280 |
| 2024-03-25 | Alice | Electronics | Laptop Stand | 12 | 360 |
| 2024-04-02 | Bob | Clothing | Hat | 40 | 320 |
| 2024-04-08 | Carol | Electronics | Charger | 50 | 1500 |
| 2024-04-14 | David | Books | AI Handbook | 15 | 525 |
| 2024-04-20 | Alice | Electronics | Mouse | 20 | 600 |
Sorting rearranges your rows based on the values in one or more columns. It does not delete anything, it just reorders.
Single column sort:
- Click any cell inside your data (e.g., F1, the Revenue header).
- Go to Data → Sort sheet → Sort sheet by column F (A to Z) for ascending (lowest first), or Z to A for descending (highest first).
- Your rows are now reordered by revenue.
Multicolumn sort (sort by Category, then by Revenue):
- Go to Data → Sort range → Advanced range sorting options.
- Check "Data has header row" so your headers don't get sorted.
- First sort column: Column C (Category), A to Z.
- Click "Add another sort column".
- Second sort: Column F (Revenue), Z to A (descending).
- Click Sort.
Result: rows are grouped by category alphabetically, and within each category the highest revenue rows appear first.
Filters hide rows that don't match your criteria, they don't delete them. Click the filter icon to reveal or rehide rows.
Turn on filters:
- Click any cell inside your data.
- Press Ctrl+Shift+L (or go to Data → Create a filter). A small dropdown arrow (▼) appears on each header cell.
- Click the ▼ on the Category header (column C).
- Uncheck everything except "Electronics". Click OK. Now only Electronics rows are visible.
Filter by condition (Revenue > 500):
- Click the ▼ on the Revenue header (column F).
- Choose "Filter by condition" → "Greater than".
- Type 500 and click OK.
- Now only rows with Revenue greater than $500 are shown.
Clear all filters:
Go to Data → Remove filter, or press Ctrl+Shift+L again to toggle the filter off entirely.
When you have 20, 100, or 1000 rows, scrolling down means your headers disappear. Freezing fixes that.
- Go to View → Freeze → 1 row. Row 1 is now frozen.
- Scroll down: your header row stays visible at the top no matter how far you scroll.
- To freeze a column (e.g., keep the Date visible): click the column header B to put your cursor in column A, then go to View → Freeze → 1 column.
- To unfreeze: go to View → Freeze → No rows (or No columns).
Data Validation restricts what can be typed into a cell. This prevents errors at the source: better to prevent a typo than to clean it up later.
Create a dropdown list for Category:
- Select the cells where you want the dropdown (e.g., C2:C100 for future data entry).
- Go to Data → Data validation.
- Under "Criteria", choose "List of items".
- Type: Electronics, Books, Clothing (comma separated).
- Enable "Show dropdown list in cell". Click Save.
- Now clicking any cell in that range shows a ▼ dropdown with your three options.
Validate a number range (Revenue must be > 0):
- Select F2:F100.
- Data → Data validation → Criteria: "Number" → "Greater than" → 0.
- Choose "Show warning" or "Reject input" for invalid entries.
- Add a custom message: "Revenue must be a positive number."
Instead of writing =SUM(F2:F21), imagine writing =SUM(Revenue). Named ranges make formulas self documenting and easier to maintain.
- Select the range you want to name, for example, F2:F21 (all Revenue values).
- Go to Data → Named ranges. A sidebar opens.
- Click "Add a range". Type the name: Revenue. Confirm the range is correct. Click Done.
- Now in any formula, you can type
=SUM(Revenue)instead of=SUM(F2:F21). - Add another: select C2:C21 and name it Category.
- Now you can write:
=COUNTIF(Category, "Electronics")which is much clearer.
Total_Revenue) or start with a number. They're case insensitive.Using the 20 row sales dataset you entered at the start of this module:
- Freeze the header row (View → Freeze → 1 row). Scroll down to confirm it works.
- Sort by Revenue descending (highest revenue first). Which product had the highest revenue?
- Turn on filters and filter the Category column to show only "Electronics". How many Electronics rows are there?
- Add a second filter: within Electronics, filter Revenue to show only rows greater than 500. Which rows remain?
- Clear your filters (Data → Remove filter) to restore all rows.
- Create a Data Validation dropdown for column C (Category): choose Electronics, Books, Clothing. Try typing a new category name, it should give you a warning.
- Name the range F2:F21 as "Revenue". Then in a blank cell, write
=SUM(Revenue)and verify it gives you the correct total.
When you apply a filter and want to sum only the visible rows, regular SUM doesn't work, it adds everything, including hidden rows. The solution is =SUBTOTAL(9, F2:F21). The number 9 tells SUBTOTAL to use SUM, but only on visible cells. Other codes: 1=AVERAGE, 2=COUNT, 5=MIN, 4=MAX.
When you use AutoSum (Σ) on a filtered range, Google Sheets automatically inserts SUBTOTAL instead of SUM, a small but thoughtful detail that saves a lot of confusion.
- Sort reorders rows by one or more columns. Use multilevel sort for complex ordering.
- Filter hides rows that don't match your criteria, it doesn't delete them. Toggle with Ctrl+Shift+L.
- Freeze rows or columns to keep headers visible while scrolling (View → Freeze).
- Data Validation restricts cell input to dropdowns, number ranges, or date constraints: preventing errors at entry.
- Named Ranges let you refer to
Revenueinstead ofF2:F21: making formulas self documenting. - Use
SUBTOTAL(9, range)instead of SUM when you want to sum only the visible (filtered) rows.