Sub topic 14
Filtering interactively with slicers and timelines
This chapter assumes you can build a PivotTable with fields in the Rows, Columns and Values areas, and that you know how the Filters area works. It uses the sales data from earlier chapters.
Date,Region,Product,Units,Sales
2025-01-05,East,Widget,10,250
2025-01-12,West,Gadget,4,180
2025-02-03,East,Gadget,7,315
2025-02-14,West,Widget,12,300
2025-03-09,East,Widget,5,125Why use slicers and timelines
A report filter in the Filters area works, but it hides the current selection inside a drop-down list. A slicer is a panel of buttons, one per item in a field. A timeline is a slicer for dates, with a horizontal scale you can drag across. Both show the current filter state on the sheet, so a reader can see what is selected without opening a menu.
| Tool | Filters by | Needs |
|---|---|---|
| Slicer | Any field, such as Region or Product | Excel 2010 or later |
| Timeline | One date field | Excel 2013 or later, and real dates |
Insert a slicer
- Click any cell inside the PivotTable.
- Open the PivotTable Analyze tab and choose Insert Slicer.
- Tick one or more fields, for example Region and Product, and select OK.
Excel adds one slicer per field. The field does not need to be in the PivotTable's layout. You can slice by Product even if Product is not in Rows, Columns or Filters.
Click a button to show only that item. The PivotTable recalculates at once. Items that are not selected turn grey.
- Ctrl+click adds or removes single items.
- Shift+click selects a continuous run of items.
- The Multi-Select button at the top right of the slicer makes every click additive, which helps on touch screens.
- The Clear Filter button, or Alt+C, removes the filter and shows all items again.
A slicer filters the data before the Values area calculates. With Region set to West, a Sum of Sales cell shows West sales only. With nothing selected, all items are included.
Format and tune a slicer
Select a slicer to open the Slicer tab. These settings are the ones you will use most:
- Columns lays the buttons out in several columns, so a slicer with 12 months can sit in a compact block.
- Button height and width control the size of the buttons.
- Slicer Styles changes colours. Pick one that keeps selected and unselected buttons clearly different.
- Slicer Settings (right-click the slicer) sets the caption, sort order, and how items with no data behave.
In Slicer Settings, two options matter in practice:
- Hide items with no data removes buttons for items that the other filters have excluded.
- Visually indicate items with no data greys those buttons out instead. Leave this on if you want the slicer to keep a stable layout.
Connect one slicer to several PivotTables
A slicer belongs to a PivotTable's data cache. PivotTables built from the same source share a cache when you create them from the same range or Table. One slicer can then drive all of them.
- Right-click the slicer and choose Report Connections. In some versions the command is called PivotTable Connections.
- Tick each PivotTable the slicer should control.
- Select OK.
If a PivotTable is missing from the Report Connections list, it uses a different cache. This usually happens when it was created from a separate copy of the data. To fix it, rebuild the PivotTable from the same Table or range as the others. Copying and pasting a PivotTable on its sheet keeps the cache, so that is the safest way to duplicate one.
Insert a timeline
A timeline filters by a date field.
- Click inside the PivotTable.
- Choose PivotTable Analyze, then Insert Timeline.
- Tick the Date field and select OK.
Drag across the scale to select a period, or drag the handles at either end to resize the selection. The drop-down at the top right switches the time level between Years, Quarters, Months and Days. At Months level, one click on February 2025 selects every row dated in that month. Click and drag across several month blocks to select a range, such as January to February.
A timeline needs a field of true dates. If the Date column holds text that looks like dates, Excel will not offer it. Convert the column with Data > Text to Columns, or with DATEVALUE, then refresh the PivotTable. The same applies to blank cells in the field. Fill them or remove those rows.
A timeline also differs from date grouping, which was covered in an earlier chapter. Grouping changes the layout of the PivotTable by adding Months or Quarters to Rows. A timeline only filters. You can use both together.
Combine slicers and other filters
Filters stack. If Region is set to West by a slicer and a Row label filter keeps only Widget, the PivotTable shows West Widget rows. If a PivotTable shows fewer rows than you expect, check these places in order:
- Each slicer for a selected button.
- The timeline for a limited period.
- The Filters area and the drop-downs on row and column labels.
A slicer button for the same field that is also in the Filters area interacts with that filter. The result is the intersection of both selections, so clear one of them if the table looks empty.
Deleted items can linger. If a region was removed from the source, its button may remain on the slicer. To remove it, right-click the slicer, choose Slicer Settings, and clear Show items deleted from the data source. Refresh afterwards.
Create a slicer with VBA
You can create a slicer in code. This macro assumes a sheet named Pivot with a PivotTable named PivotTable1. It adds a Region slicer next to it.
Sub AddRegionSlicer()
Dim ws As Worksheet
Dim pt As PivotTable
Dim sc As SlicerCache
Set ws = ThisWorkbook.Worksheets("Pivot")
Set pt = ws.PivotTables("PivotTable1")
Set sc = ThisWorkbook.SlicerCaches.Add2(pt, "Region")
sc.Slicers.Add ws, , "RegionSlicer", "Region", 20, 400, 140, 120
End SubThe last four numbers are the slicer's top, left, width and height in points. Run the macro once. A second run creates a duplicate slicer cache and may fail on the name.
Common problems
- Clicking a button changes nothing. The slicer is not connected to that PivotTable. Check Report Connections.
- A slicer button is missing. Refresh the PivotTable. If the item never existed in the source, there is no button.
- The timeline option is greyed out. The active cell is outside a PivotTable, or the Date field has text or blanks.
- Slicers cover cells. They float over the sheet. Move them to a spare area, or use the Size and Properties options to stop them moving with cells.
Exercise
You built two PivotTables from the same Table: sales by product and sales by month. You add a Region slicer to the first, but clicking West leaves the second one unchanged. What do you do, and what does it tell you if the second PivotTable is not listed in the dialog you open?
Show answer
Right-click the slicer, open Report Connections, and tick the second PivotTable, then select OK. If it is not listed, it uses a different data cache, so the slicer cannot reach it. Rebuild the second PivotTable from the same Table, or copy the first PivotTable, so that both share one cache.
Exercise
You add a Date timeline at Months level and select January 2025 to February 2025 in the sample data. Which rows remain, and what is the Sum of Sales?
Show answer
Four rows remain: 2025-01-05, 2025-01-12, 2025-02-03 and 2025-02-14. The sum is 250 + 180 + 315 + 300 = 1,045. The 2025-03-09 row is excluded.