Forum Discussion

rcarhart2's avatar
rcarhart2
Frequent Visitor
1 year ago
Solved

Switch statement with numeric what if parameter

I created a simple numeric what if parameter from 1-12. it is called Date_names I then want to use a switch statement to display this as: SWITCH([Date_Names Value],     1, "Last Month vs Prior Mo...
  • Poojara_D12's avatar
    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:

    1. 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].

    2. 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