Find a course

Module 3: Logic, Lookups and Clean DataLesson 8 of 1212 min

Sort, Filter, Validate and Clean

Sort and filter without scrambling rows, use filter views in shared sheets, add dropdown lists, and clean messy data with TRIM, SPLIT and remove duplicates.

Step 1 of 10Learn

The sort that scrambled everything

Ben wanted his volunteer list in alphabetical order. He selected column A, the names, and sorted it A to Z. The names moved. The phone numbers and email addresses in columns B and C did not. Suddenly every volunteer had someone else's phone number, and he only noticed after texting the wrong people.

Sorting must always move whole rows together. Two safe ways to do it in Sheets:

  1. Click any single cell in the column you want to sort by, then choose Data > Sort sheet > Sort sheet A to Z. This sorts every row of the sheet by that column. Freeze your header row first (View > Freeze > 1 row), or the header gets sorted into the data.
  2. Select the entire table, including all columns, then choose Data > Sort range > Advanced range sorting options. Tick "Data has header row," choose the column and the order, and add a second sort column if needed, such as Region then Sales from largest to smallest.

Text sorts A to Z or Z to A, numbers smallest to largest or the reverse, and dates oldest to newest. If numbers sort strangely, such as 100 before 25, they're probably stored as text.

If a sort does go wrong, press Ctrl+Z immediately. That's also a good reason to keep an ID or row-number column in important lists: you can always sort by it to restore the original order.

Sorting only the name column scrambles the table: before sorting, Zoe, Ann and Max each have their own phone number; after sorting just column A, the names move but the phones stay, so every name gets the wrong numberBeforeAB1234NamePhoneZoe555-0101Ann555-0102Max555-0103After sorting column A onlyAB1234NamePhoneAnn555-0101Max555-0102Zoe555-0103Ann now has Zoe's number. Select the whole table before sorting.

Step 2 of 10Practice · What would you do?

What would you do?

Your customer table has names in column A, cities in B and phone numbers in C, with a frozen header row. You want it sorted by city. What should you do?

Step 3 of 10Learn

Filters and filter views

A filter temporarily hides rows that don't match what you're looking for, without deleting anything. Click any cell in your table and choose Data > Create a filter. A small filter icon appears in each header cell. Click one to:

  • Filter by values: tick only the items you want, such as the city Denver.
  • Filter by condition: show rows where a number is greater than 500, text contains a word, or a date is after a certain day.
  • Sort from the same menu.

Row numbers of hidden rows disappear from the left margin, and the header shows a funnel icon on filtered columns, reminders that you're seeing only part of the data. Turn the filter off with Data > Remove filter.

In a shared spreadsheet there's a catch: a normal filter changes the view for everyone who has the file open. If you filter to your region, your colleague suddenly sees only your region too.

Filter views solve this. Choose Data > Filter views > Create new filter view. The header turns dark gray, and any sorting or filtering you do now affects only your screen. Name the view, such as "Denver open orders," and it's saved for later; you can even share a link that opens the sheet with that view applied.

A useful detail: functions like SUM still include hidden rows. To total only visible rows after filtering, use =SUBTOTAL(109, C2:C500), where 109 means sum while ignoring hidden rows.

Step 4 of 10Practice · True or false

In a shared spreadsheet, a filter view lets you filter the data without changing what your collaborators see.

Step 5 of 10Compare

Filter vs. filter view

AspectFilter (Data > Create a filter)Filter view
Who sees the resultEveryone who has the file openOnly you
How it looksFunnel icons in the header rowDark gray header around the sheet
SavingOne active filter per sheetSeveral named views, each with its own link
Best forFiles you work on aloneShared files with several people working at once

Step 6 of 10Learn

Dropdowns and data cleanup

Clean data is much easier to keep clean than to fix. Dropdown lists stop typos at the source. Select a column of cells, choose Insert > Dropdown, and type the allowed options, such as Not started, In progress and Done. Each cell then offers a menu, and Sheets can reject or flag anything else. More rules live under Data > Data validation: numbers within a range, valid dates, checkboxes or emails.

For data that's already messy, Sheets has cleanup tools:

  • TRIM removes extra spaces: =TRIM(A2) turns " Denver " into "Denver."
  • PROPER, UPPER and LOWER fix capitalization: =PROPER("jOHN sMITH") gives "John Smith."
  • SPLIT breaks text apart at a delimiter: =SPLIT(A2, ",") separates "Lopez, Maria" into two cells. The menu version is Data > Split text to columns.
  • Data > Data cleanup > Remove duplicates deletes repeated rows after letting you choose which columns define a duplicate.
  • Data > Data cleanup > Trim whitespace trims a whole selection at once.
  • Find and replace (Ctrl+H) swaps one value for another across the sheet, such as "Calif." for "California."

When you clean with formulas, the cleaned values live in a new column. To replace the original, copy the new column and paste with Edit > Paste special > Values only (Ctrl+Shift+V). Then you can delete the helper column without breaking anything.

Step 7 of 10Practice · Match the pairs

Match each messy-data problem with the best tool.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. " Chicago " has extra spaces
  2. "smith, anna" needs proper capitalization
  3. "Smith, Anna" should be two columns
  4. The same customer row appears three times
  5. People keep typing "Compleet" instead of "Complete"

Step 8 of 10Tap to reveal

A five-minute cleanup routine for imported data

  1. 1. Make a copy

    Duplicate the tab (right-click > Duplicate) before cleaning, so you can always compare against the original.

  2. 2. Trim and fix types

    Run Data > Data cleanup > Trim whitespace. Then check alignment: numbers or dates hugging the left edge are text and need converting via Format > Number.

  3. 3. Standardize labels

    Use the filter menu on each text column to see every distinct value. Fix variants like "NY," "N.Y." and "New York" with Find and replace.

  4. 4. Remove duplicates

    Use Data > Data cleanup > Remove duplicates, choosing the columns that identify a unique record, such as Email.

  5. 5. Lock it down

    Add dropdowns or validation to the columns people type into, so the data stays clean from now on.

Step 9 of 10Practice · Choose one

You cleaned names with =PROPER(TRIM(A2)) in column F. You now want to delete the original column A. What must you do first?

Step 10 of 10Practice · Select all that apply

Which statements about sorting and filtering in Google Sheets are true? Select all that apply.

Select all that apply.