Forum Discussion
Switch statement with numeric what if parameter
- 1 year ago
Hi rcarhart2
The issue you’re encountering is likely due to referencing the What-If parameter incorrectly in your SWITCH statement. When you create a What-If parameter in Power BI, it generates a table and a measure associated with that parameter. Typically, the measure representing the parameter's selected value is named something like [ParameterName Value], where "ParameterName" is the name you gave the parameter.
Here’s how to correctly reference the parameter in your SWITCH statement:
Verify Parameter Measure Name: Check the Fields pane in Power BI to confirm the exact name of the measure for your What-If parameter. It should appear under the parameter table with a name like [Date_names Value].
Update the SWITCH Statement: Use this measure in your SWITCH statement as shown below:
SWITCH( [Date_names Value], 1, "Last Month vs Prior Month", 2, "Last Quarter vs Prior Quarter", 3, "Last Month YOY", 4, "Last Quarter YOY", 5, "Last Year vs Prior Year", 6, "MTD vs Prior MTD", 7, "QTD vs Prior QTD", 8, "YTD vs Prior YTD", 9, "Rolling 30 Days", 10, "Rolling 12 Months", 11, "Custom", 12, "Last Week YOY", "Invalid Selection" // Optional default case )Common Issues to Check:
- Correct Measure Name: Ensure [Date_names Value] matches the measure name exactly. It’s case-sensitive, so ensure capitalization is correct.
- Data Type: Confirm that [Date_names Value] is numeric (which it should be, as it’s from a What-If parameter).
- Default Case: Adding a default case (e.g., "Invalid Selection") at the end can sometimes help troubleshoot unexpected results.
Let me know if this resolves the issue!
Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂
Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
YouTube: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
Poojara_D12 Thank you. I was also doing this in dax when it was a measure. thank you for your reply.
rcarhart2 Glad to hear that!! 🙂