Sub topic 9
Sorting and filtering results
This chapter assumes you can insert a PivotTable and place fields in the Rows, Columns, Values and Filters areas. It uses the sample data from earlier chapters: Date, Region, Product, Units and Sales. Sorting controls the order of items. Filtering controls which items appear. Both change only the PivotTable view. The source data is never altered.
Sorting in a PivotTable
You can sort row labels, column labels, or the values themselves. The sort applies to the field, not to a fixed cell range. When the layout changes or the data refreshes, Excel re-applies the rule.
Sorting by labels
Click the drop-down arrow on a row or column label cell. Choose Sort A to Z or Sort Z to A. Text sorts alphabetically, numbers numerically and dates chronologically.
Sorting by values
To rank regions by sales, right-click any Sales value in the Region rows. Choose Sort, then Sort Largest to Smallest. Excel sorts the Region items by that value column.
With both rows and columns in play, the sort uses the column you clicked. In a Region by Product grid, right-clicking a Widget value sorts regions by Widget sales. It does not sort by the grand total unless you click in the Grand Total column.
Sort options and manual order
Open the field's drop-down and choose More Sort Options. There you can choose:
- Manual, which lets you drag items into any order.
- Ascending or Descending by a chosen field, such as Sum of Sales.
- More Options, where you can turn off Sort automatically every time the report is updated.
Manual order is useful for items with a natural sequence that does not sort alphabetically, such as "Low, Medium, High". You can also type over an item label, or drag it to a new position in the grid.
Months are a common case. If the field holds real dates grouped by month, they sort chronologically. If it holds month names as text, they sort alphabetically unless Excel's built-in custom lists apply. Excel does recognise month and weekday names by default.
Filtering in a PivotTable
There are four main filter types. Each answers a slightly different question.
| Filter type | Where you set it | What it does |
|---|---|---|
| Label filter | Drop-down on a row or column field | Keeps items whose names match a rule, such as begins with "W" |
| Value filter | Drop-down on a row or column field | Keeps items whose total meets a rule, such as Sum of Sales greater than 300 |
| Manual selection | Check boxes in the drop-down | Keeps only the items you tick |
| Report filter | Field in the Filters area | Restricts the whole PivotTable to chosen items |
Manual selection
Click a field's drop-down arrow, clear Select All, then tick the items to keep. Hidden items vanish from the grid, and grand totals recalculate to include only the visible items.
Label filters
Choose Label Filters in the drop-down. Options include Equals, Begins With, Contains and, for date fields, Dates Filters such as This Month or Between. Label filters work on item names, not on numbers.
Value filters
Choose Value Filters, then pick a rule such as Greater Than or Between. Excel compares each item's aggregated value. For example, "Region where Sum of Sales is greater than 400" tests the total for each region, not individual records.
Top 10 filters
Value Filters, then Top 10, keeps the highest or lowest items. Despite the name, you choose the number. You can also choose Items, Percent or Sum:
- Items keeps a fixed count, for example the top 3 products.
- Percent keeps the top share of items.
- Sum keeps items until their combined value reaches a target.
Top 10 is evaluated against a chosen value field, so with several value fields you must select the right one.
Report filters
Drag a field such as Region into Filters. A drop-down appears above the PivotTable. Pick one item, or tick Select Multiple Items to pick several. Use a report filter when you want to slice the whole report by a field without showing that field in the grid.
If you need one sheet per item, choose PivotTable Analyze, Options, Show Report Filter Pages. Excel creates a worksheet for each item.
Combining sorting and filtering
Sorting and filtering work together. A common request is "the three best regions by sales, largest first". Do this:
- Put Region in Rows and Sum of Sales in Values.
- Open the Region drop-down, choose Value Filters, then Top 10.
- Set Top, 3, Items, Sum of Sales, then click OK.
- Right-click a Sales value and choose Sort, Sort Largest to Smallest.
The Top 10 filter selects the items. The sort then orders them.
One filter type per field
A field can have only one of these active at a time by default: a label filter, a value filter, or a manual selection. Applying a new one clears the previous one. To combine them, open PivotTable Analyze, Options, Totals & Filters, and enable Allow multiple filters per field.
Filters and grand totals
By default, filtered-out items are not included in the totals. Excel offers Include Filtered Items in Totals on the Design tab, under Subtotals, but that setting is limited to certain data sources. It is not available for a standard range or Table source. If your totals look smaller than the full dataset, that is expected behaviour.
Clearing and reapplying filters
To remove a filter from one field, open its drop-down and choose Clear Filter From "Field". To remove all filters and sorts at once, choose PivotTable Analyze, Clear, Clear Filters.
New items that appear after a refresh are handled according to the filter type:
- With a manual selection, new items are normally hidden or shown depending on the field's state when the filter was applied. Check the field after a refresh.
- With label or value filters, new items are evaluated against the rule automatically.
Rule-based filters are therefore safer than manual ticks when the data changes often.
Common problems
- A sort does not stick. Check that Sort automatically every time the report is updated is on. If you dragged items manually, the order may be set to Manual.
- Dates sort as text. The source column holds text, not true dates. Convert the column, then refresh.
- The Value Filters option is greyed out. A value filter needs at least one field in Values. It also needs the filtered field to be in Rows or Columns.
- A filter seems to ignore items. Another field in Filters, or a slicer, may be limiting the same data. Clear each in turn.
- Top 10 returns more items than expected. Ties are all kept, so equal values at the cut-off can add extra items.
Exercise
A PivotTable shows Region in Rows and Sum of Sales in Values. You want only regions whose total sales exceed 300, shown from largest to smallest. Which filter type do you use, and how do you order the result?
Show answer
Use a value filter. Open the Region drop-down, choose Value Filters, then Greater Than, select Sum of Sales and enter 300. Then right-click a Sales value and choose Sort, Sort Largest to Smallest. The value filter tests each region's total, not individual records, and the sort orders the regions that remain.
Exercise
You applied a Top 10 filter to Product, then tried to add a label filter on the same field, and the Top 10 filter disappeared. Why, and how do you keep both?
Show answer
By default a field supports only one filter type at a time, so a new filter replaces the old one. To keep both, go to PivotTable Analyze, Options, Totals & Filters, and tick Allow multiple filters per field.