Sub topic 2
Adding and using slicers
This chapter assumes you can open a report in Power BI Desktop or the Power BI service and add a visual to a page. It also assumes you know the difference between a table, a column, and a measure in the data model. You do not need to know DAX yet. Later chapters cover slicer types, formatting, and the Filter pane in more detail. Here the focus is the working model of a slicer and the errors people hit most often.
What a slicer is
A slicer is a visual that lets report readers choose values from a field and narrow the data shown in other visuals on the page. It sits on the canvas, so readers can see what is selected without opening a menu. This is the main difference from the Filter pane, which is a side panel that readers expand when they need it.
Under the hood, a slicer is a filter that the reader controls. When you select "Bikes" in a Category slicer, Power BI adds the condition Category = "Bikes" to the filters used by the other visuals on that page. Each visual then recalculates its values with that condition applied.
The previous chapter introduced filter context, which is the set of filters that apply to a calculation. A slicer selection becomes part of the filter context for every visual it affects.
Add a slicer
You need a report page with at least one visual and a table that contains a column to filter by. The steps are the same in Power BI Desktop and in the service when you are editing a report.
- Click an empty area of the report canvas so that no visual is selected.
- In the Visualizations pane, select the Slicer icon. An empty slicer appears on the canvas.
- From the Data pane, drag a field into the slicer's Field well. You can also select the field's checkbox while the empty slicer is selected.
- Resize and move the slicer so it does not cover other visuals.
If you click a field in the Data pane while an existing visual is selected, Power BI adds the field to that visual instead. Deselect everything first.
Power BI chooses a default slicer style based on the field's data type. A text field such as Product[Category] produces a vertical list with checkboxes. A date field produces a range slider. The next chapter covers the available styles and which fields suit each one.
Use a slicer
Selecting a value in a slicer filters the page immediately. The following table shows the default interactions for a list slicer.
| Action | Result |
|---|---|
| Click one value | Only that value is selected. Other visuals show data for it. |
| Click a different value | The selection switches to the new value. |
| Ctrl + click additional values | Adds values to the selection (multi-select). |
| Click the selected value again | Clears the selection. |
| Click the eraser icon on the slicer | Clears all selections in that slicer. |
When nothing is selected, the slicer does not filter at all. Every value is included. This matters when you read a visual: an empty slicer means "all values," not "no values."
Slicers also respond to each other. If you have a Year slicer and a Month slicer, choosing a year makes the Month slicer show only months that have data for that year in the model's relationships. How a slicer's list changes depends on the relationships between tables, which is covered in the troubleshooting chapter.
Which visuals a slicer affects
By default, a slicer filters all other visuals on the same page. It does not filter visuals on other pages. Two other behaviors are worth knowing now.
- A slicer does not filter itself. Selecting a value does not hide the other values in the same slicer, unless another slicer or filter has removed them.
- A slicer filters a visual only if the slicer's field is connected to the visual's data through a relationship in the model, or if the field comes from the same table.
The second point explains many "my slicer does nothing" reports. If a slicer uses a column from a table that has no relationship to the table behind a visual, selecting a value changes nothing in that visual.
The following diagram shows the path a selection takes.
A worked example
Suppose your model has a Sales fact table and a Product dimension table, with a one-to-many relationship from Product[ProductKey] to Sales[ProductKey]. A column chart shows total sales by month.
- Add a slicer and drag
Product[Category]into it. - Select Bikes. The column chart now shows only sales of bikes.
- Ctrl + click Accessories. The chart shows bikes plus accessories combined.
- Click the eraser icon. The chart returns to all categories.
The filter reaches Sales because it travels from the Product table along the relationship toward the Sales table. A measure such as the following is recalculated for each month under the current slicer selection:
Total Sales = SUM ( Sales[SalesAmount] )The measure itself never changes. The same definition returns a different number in each visual because each visual has a different filter context. That context combines the slicer selection, the month on the chart's axis, and any other filters on the page.
You can also display the current selection as text. This measure returns the chosen category, or a fallback message when none or several categories are selected:
Selected Category =
SELECTEDVALUE ( Product[Category], "All categories" )Put it in a card visual or use it in a title, and readers can see what the slicer is doing without looking at the slicer itself. The final chapters return to this measure and to other measures that react to slicers.
Search, hierarchy, and other options on a list slicer
A list slicer has a few controls that matter on large fields.
- Search. Open the slicer's More options menu (the three dots) and choose Search. A search box appears at the top of the slicer. This is useful for fields with hundreds of values, such as customer names.
- Sort. In the same menu, choose Sort ascending or Sort descending, and pick whether to sort by the field or by another measure or column.
- Select all. In the Format pane, under the slicer's selection settings, turn on Select all. This adds a "Select all" option at the top of the list.
Readers can also reset a slicer. In Power BI Desktop and the service, the eraser icon clears the selection in that slicer only. To clear every slicer and filter on a page, readers can use the Reset to default button in the report's header toolbar, which restores the report to the state the author saved. Selections made in the slicer do not change the saved report unless you save them as the author.
Common errors
- The slicer does nothing. The slicer's field has no relationship to the visual's table, or the interaction between the slicer and the visual has been turned off. Check the model view first, then check the interaction settings, which a later chapter covers.
- The slicer shows values, but the visual goes blank. The selected value has no matching rows once the other filters on the page are applied. Clear other slicers to confirm.
- A new field replaced the old one. If you drop a second field into the slicer's Field well, Power BI creates a hierarchy-style slicer or replaces the field, depending on the slicer type. Remove the extra field if you did not intend this.
- A slicer filters a measure that ignores it. If a measure uses
REMOVEFILTERS, the slicer has no effect on that measure by design. The last chapter on DAX explains this. - Selections disappear when you reopen the report. Slicer selections made by readers are not saved to the published report. They persist in a reader's session only if personal bookmarks or "persistent filters" are available in the service. Authors can save a default selection by selecting the slicer value and then saving the report.
Summary of the working model
A slicer is a visible filter that the reader controls. It adds a condition to the filter context of every other visual on its page that is connected to the slicer's field through the data model. An empty slicer filters nothing. Measures are recalculated under the new context, so the same measure gives different results in different places.
Exercise
A report page has a Category slicer built from Product[Category] and a card showing Total Sales. You select "Bikes" and the card does not change. Name two things you would check, and say which one you would check first.
Show answer
Check first whether the Product table has a relationship to the Sales table, in the model view, because a slicer can only filter tables it is connected to. Then check whether the interaction from the slicer to the card has been turned off in Edit interactions. You could also check whether the measure uses a function such as REMOVEFILTERS that ignores filters on the Product table.
Exercise
In the Category slicer, no values are selected. Does the report show no data, or all data? Explain why.
Show answer
It shows all data. A slicer with no selection adds no filter condition, so every value in the field is included.