Forum Discussion
Change slicer fields based on a different slicer selection
To achieve this functionality in Power BI, you can create a dynamic measure slicer that changes based on the selection in the first slicer. Here's how you can do it step by step:
---
Step 1: Create a Field Parameter for the Second Slicer
1. Go to the **Modeling** tab in Power BI and click on **New Parameter** > **Fields**.
2. Create two field parameters:
- **Comparison1**: Includes `PriorDayUnits`, `PriorWeekUnits`, `PriorMonthUnits`, `PriorYearUnits`.
- **Comparison2**: Includes `PriorDayGrossSales`, `PriorWeekGrossSales`, `PriorMonthGrossSales`, `PriorYearGrossSales`.
---
Step 2: Create a Measure to Dynamically Switch Between Field Parameters**
Create a measure that dynamically selects the appropriate field parameter based on the selection in the first slicer (`TotalUnits` or `TotalGrossSales`).
```DAX
DynamicComparison =
SWITCH(
SELECTEDVALUE('DynamicMeasure'[Measure]), // Replace 'DynamicMeasure' with the name of your first slicer table
"TotalUnits", SELECTEDVALUE(Comparison1[Comparison1]),
"TotalGrossSales", SELECTEDVALUE(Comparison2[Comparison2])
)
```
---
Step 3: Create the Second Slicer**
1. Add a slicer to your report.
2. Bind the slicer to the **DynamicComparison** measure.
3. This slicer will now dynamically show either the `Comparison1` or `Comparison2` options based on the selection in the first slicer.
---
Step 4: Configure Interactions Between Slicers**
1. Ensure that the first slicer (`TotalUnits` or `TotalGrossSales`) is connected to the second slicer.
2. Use the **Edit Interactions** feature in Power BI to control how the first slicer filters the second slicer.
---
Step 5: Test the Dynamic Behavior**
- Select `TotalUnits` in the first slicer, and the second slicer should display `PriorDayUnits`, `PriorWeekUnits`, `PriorMonthUnits`, `PriorYearUnits`.
- Select `TotalGrossSales` in the first slicer, and the second slicer should display `PriorDayGrossSales`, `PriorWeekGrossSales`, `PriorMonthGrossSales`, `PriorYearGrossSales`.