Power BI Filter All Selected Guide
Yes, you can filter all selected items in Power BI Desktop to exclude them from a visual or calculation, or to apply a specific context to a group of rows at once. This requires using a DAX measure that checks the visual's selection state or a slicer selection state using the SELECTEDVALUE or VALUES functions combined with logical checks. You will need a working Power BI Desktop installation with data loaded into the Data Model and a report page created.
What You'll Need
- A computer with Power BI Desktop installed.
- A data model loaded into Power BI Desktop.
- A report page with at least one visual and a slicer using a categorical field.
Step-by-Step
- Open your Report and Data Model. Launch Power BI Desktop and load your dataset. Navigate to the Report view where you want to apply the filter.
- Create a Slicer for the Category. From the Fields pane, drag a categorical field (e.g., Region, Product Category, or Customer Name) to the canvas. Power BI will automatically create a default slicer visual.
- Understand the Goal. Decide exactly what you want to achieve. There are two common scenarios:
-
- Scenario A (Exclude All Selected): You want to filter out every item currently selected in the slicer from a specific visual (e.g., show sales for all products except the selected ones).
- Scenario B (Filter Only All Selected): You want a visual to show data only when the user has selected multiple items (or all items) in the slicer, and return blank or zero otherwise.
- Create the Measure for Scenario A (Exclude All Selected). Click the New Measure button on the ribbon. Enter the following DAX code. This measure calculates the sum of sales but excludes any rows where the selected value matches the context.
-
Exclude Selected Sales = CALCULATE([Total Sales], ALLSELECTED('TableName'[CategoryColumn])) -
- Explanation:
CALCULATEevaluates the expression with the specified filters.ALLSELECTED('TableName'[CategoryColumn])removes any filters applied to that column by the slicer, effectively resetting the context for that specific column while keeping other filters (like Date or Region) intact. This results in the total sales, but without the contribution of the items selected in the slicer. - Apply the Measure: Drag your new measure into a Table or Card visual. Observe that the total now represents the sum of all items minus the items currently selected in the slicer.
- Explanation:
- Create the Measure for Scenario B (Filter Only All Selected). Click New Measure again. Use this DAX code to filter the visual to show data only when the user has selected multiple items.
-
Filter Only Selected = VAR SelectedCount = DISTINCTCOUNT('TableName'[CategoryColumn]) RETURN IF(SelectedCount > 1, [Total Sales], BLANK()) -
- Explanation:
VAR SelectedCountcreates a variable to count the unique items selected in the slicer.IF(SelectedCount > 1, ...)checks if more than one item is selected. If true, it returns the[Total Sales]measure; otherwise, it returnsBLANK(), which typically renders as an empty space in the visual. - Apply the Measure: Drag this measure into a visual. You will see the data appear and disappear dynamically as you select and deselect items in the slicer. It will show results only when you have more than one item selected.
- Explanation:
- Applying the Filter to a Specific Visual. If you want to apply the exclusion or inclusion logic to a specific visual without affecting the entire report, use the Visual interactions feature.
-
- Update the Measure: Modify the measure from Step 5 or 7 to include the specific visual's column name in the
ALLSELECTEDfunction. For example:Exclude Selected Sales - Visual = CALCULATE([Total Sales], ALLSELECTED('TableName'[CategoryColumn], 'TableName'[VisualColumn])). - Set Visual Interactions: Click the specific visual you want to filter. Go to the Format tab on the ribbon and click the Visual interactions button (it looks like a chain link icon). In the pane that appears on the right, toggle the slicer off for the specific visual. This creates a one-way filter where the slicer filters the rest of the report but not this specific visual.
- Combine with Measure: Add the measure created in Step 5 to this specific visual. The combination of the one-way visual interaction and the DAX measure will achieve the desired result of filtering out the selected items for that single visual.
- Update the Measure: Modify the measure from Step 5 or 7 to include the specific visual's column name in the
Common Mistakes
Mistake 1: Using ALL() instead of ALLSELECTED(). The ALL() function removes all filters from the table or column, which is too aggressive. It will treat the report as if no slicers are active at all. ALLSELECTED() is necessary to remove only the filters introduced by the slicer while preserving other filters like Date or Region.
Mistake 2: Not Handling Single-Selection. If your goal is to exclude only when multiple items are selected, simply checking SELECTEDVALUE might not be enough. SELECTEDVALUE returns a single value or BLANK. You must use DISTINCTCOUNT or VALUES to handle the case where two or more items are selected.
Mistake 3: Forgetting Visual Interactions. Applying a DAX measure like ALLSELECTED affects the entire data model. If you want the filter to apply only to a single chart, you must also use the Visual Interactions pane to prevent the slicer from affecting that specific visual.
Tips
Tip 1: Use Variables for Readability. When writing complex DAX, use the VAR keyword to break down logic into smaller, more understandable parts. This makes your measures easier to debug and maintain.
Tip 2: Understand the Filter Context. Always ask yourself: what filters are currently active? ALLSELECTED preserves the filter context of the entire visual, while REMOVEFILTERS can be used to remove specific filters on specific columns.
Tip 3: Test with a Single Item. Before assuming your measure works for multiple selections, test it with a single item selected. Sometimes a measure that works for multiple items will return incorrect or unexpected results with a single selection.
Troubleshooting
Problem: The measure returns the same value whether an item is selected or not.
Diagnosis: This usually happens because the slicer is not correctly linked to the category column used in the measure. Ensure that the column name in the slicer matches the column name used in the ALLSELECTED function exactly, including case sensitivity.
Problem: The visual shows blank or zero when it should show data.
Diagnosis: For Scenario B, check if the measure is using BLANK() correctly. The visual might be configured to hide empty values. Try adding a conditional formatting rule to show a specific color, such as light gray, when the value is BLANK, to confirm the logic is working.
Problem: The total sum of the report does not match the sum of the visual.
Diagnosis: This is a sign of a circular filter or a misunderstanding of filter propagation. Ensure you are not applying a measure that filters the entire data model to a visual that is itself being filtered by the slicer. Check the Visual Interactions pane to ensure no unintended one-way filters are active.