fx Data Cleaning

Sort, Filter, custom sort lists

⏱ 9 min

What you'll learn

  • Sort complete records by custom region order and descending amount.
  • Combine filters and use SUBTOTAL for visible amounts/counts.
  • Copy visible rows while preserving row integrity and the source data.

Concept

1. The golden rule of sorting

Click one cell inside the data (don't select a single column). Excel then selects the whole table and keeps each row together.

If you select just one column and sort, Excel warns "Expand the selection?". Always choose Expand. "Continue with the current selection" sorts only that column and mixes up your data — Rahul's sales end up in Neha's row.

2. Quick sort

Data → A→Z or Z→A sorts by the column of the active cell.

3. Multi-level sort

Data → Sort:

  1. Sort by Region, A to Z.
  2. Add Level → then by Sales, Largest to Smallest.

Result: regions together, and within each region the top seller first. Make sure My data has headers is ticked.

You can also sort by Cell Color or Font Color — useful after highlighting duplicates (Lesson 1).

4. Custom sort order

Alphabetical order isn't always right: East, North, South, West or High, Low, Medium look odd.

In the Sort dialog → Order → Custom List… → type your order, one per line:

High
Medium
Low

→ Add → OK. Now sort follows this order. Days of the week and months are already built in.

To reuse a list in every file: File → Options → Advanced → Edit Custom Lists. Bonus: type "High" and drag the fill handle — Excel fills Medium, Low.

5. Filter

Turn on: Ctrl + Shift + L (or Data → Filter). Arrows appear on the headers.

Filter type Example
Text Filters Contains "Sharma", Begins with "P10"
Number Filters Greater than 50000, Top 10, Above Average
Date Filters This Month, Last Quarter, or tick months in the tree
By colour only red (duplicate) cells

Filters on several columns work together (AND): Region = North and Sales > 50000.

Clear everything: Data → Clear. A funnel icon on a header shows which column is filtered.

6. Totals that follow the filter — SUBTOTAL

SUM adds hidden rows too. Use:

=SUBTOTAL(9, E2:E500)     → sum of visible rows only
=SUBTOTAL(3, A2:A500)     → count of visible non-blank rows

SUBTOTAL ignores rows hidden by a filter. Use 109 instead of 9 to also ignore rows you hid manually.

7. Copy only the visible rows

Filter → select the result → Alt + ; (select visible cells only) → Copy → Paste. Otherwise hidden rows can get copied too in some cases.

8. Excel 365: SORT and FILTER functions

=SORT(A2:E100, 5, -1)            → sorted by column 5, largest first
=FILTER(A2:E100, C2:C100="North")

They create a live sorted/filtered copy that updates with the data. Covered in detail in a later track.

Common mistakes

Sorting one column only. Headers getting sorted into the data (My data has headers unticked). Using SUM on filtered data and reporting the wrong total. Forgetting a filter is on and thinking rows are missing.

Exercises

mediumUsing the sales sheet from Module 3, Lesson 6 (Date, Salesperson, Region, Product, Amount), sort by Region in the custom order North, South, East, West, then by Amount largest first. Filter Laptop sales above 40000, show the total with SUBTOTAL, and copy only the visible rows to a new sheet.
On Sales, sort the entire A1:E8 range by Region in North,South,East,West order, then Amount descending. Sorted amounts: 55000,22000,15000,48000,30000,18000,61000. East has no rows. Filter Product = Laptop and Amount >40000. H2: =SUBTOTAL(9,E2:E8) gives 164000; H3: =SUBTOTAL(3,A2:A8) gives 3. SUM remains 249000 even while filtered. Use Alt+; on the selected visible data, then copy into Visible Rows A2:E4. After clearing filters, SUBTOTAL returns 249000. 109 also excludes manually hidden rows; 9 excludes filtered rows but includes manually hidden ones. Sorted Answer and Answers provide independent checks.

Quiz

Safest way to start a sort?
Click one cell inside the data
Shortcut to toggle filters?
Ctrl + Shift + L
Which function totals only visible rows?
SUBTOTAL
Sort, Filter, custom sort lists · Foundations | ExcelWalaa