Forum Discussion
How to toggle with slicer in Power BI
Hi Everyone,
I have a table which is shown below for FY25.
I have a table called Selected_Measure_2, in which I would like to use to toggle between "Grand Total" and "YTD Total".
How do I set it up so that when "YTD Total" is selected in the slicer, the matrix above displays data from Jul 24 to MMM YY?
Also, when "Grand Total" is selected in the slicer, the matrix above displays the whole Financial Year?
My DAX is also provided, just in case it needs tweaking.
Thanks,
Arnie.
1 Reply
- grazitti_sapna
Super User
Hi arnie ,
To set up a toggle slicer in Power BI so that selecting "YTD Total" or "Grand Total" dynamically adjusts the matrix, follow these steps:Steps to Implement:
- Create a Measure for Conditional Display Modify or create a measure that evaluates the slicer selection and adjusts the data displayed based on the selection.
Here’s how to create the toggle functionality:- Assume the slicer uses the View column from the Selected_Measure_2 table.
- Use the following DAX to create a conditional measure
Toggle Total =
VAR CurrentSelection = SELECTEDVALUE('Selected_Measure_2'[View])
VAR CurrentDate = TODAY()
VAR CurrentMonthYear = FORMAT(CurrentDate, "YYYYMM")
VAR StartMonthYear = "202407" -- Replace this with the start of your financial year
VAR YTDTonnes =
CALCULATE(
[_Calc. Budget],
'Date'[Year-Month Code] >= StartMonthYear,
'Date'[Year-Month Code] <= CurrentMonthYear
)
VAR GrandTonnes =
CALCULATE(
[_Calc. Budget],
'Date'[Year-Month Code] >= StartMonthYear
)
RETURN
SWITCH(
TRUE(),
CurrentSelection = "YTD Total", YTDTonnes,
CurrentSelection = "Grand Total", GrandTonnes,
BLANK()
)
- Adjust the Matrix to Use the New Measure Replace your existing measure in the matrix visual with the Toggle Total measure.
Set Up the Slicer
Add a slicer to your report and bind it to the View column from the Selected_Measure_2 table.
Ensure it displays the options YTD Total and Grand Total.
Format the Matrix for Correct Display
Ensure your matrix rows and columns are configured with fields like Product Type, Order Group, and Year-Month to properly summarize the data.
Explanation of the Logic:
- YTD Total: The measure filters the data from the start of the financial year (StartMonthYear) up to the current month (CurrentMonthYear).
- Grand Total: The measure displays the full-year data without restricting the date range.
Testing:
- Select "YTD Total" in the slicer to ensure only data up to the current month (e.g., Jul 24 to the current MMM YY) is displayed.
- Select "Grand Total" to ensure the full financial year is displayed.
If adjustments are needed for the _Calc. Budget measure or for the financial year logic, update the respective sections in the Toggle Total DAX formula.
If I have resolved your question, please consider marking my post as a solution. Thank you! - Create a Measure for Conditional Display Modify or create a measure that evaluates the slicer selection and adjusts the data displayed based on the selection.