Forum Discussion

Steve_Scotland's avatar
1 year ago
Solved

Using SWITCH or IF for parameters required for the table in DAX Filter

I have the following two examples of Calculations using a FilteredDates VAR in my Measures for a FILTER The only difference is what I am passing to the filter ie for Week TY I am passing ALL...
  • Steve_Scotland's avatar
    Steve_Scotland
    1 year ago

    sevenhills 

    It turns out the solution was to put the SWITCH in to the Filter as per the below

    Fluctuating between VERY pleased  &  annoyed.
    Will have to do reams of testing.   I'm worried it comes under the header of "Shouldn't work but does" - ha ha.  

    For this example, I've changed the VAR  Calcs_Needed      to      SelectedTimeFrame
    Apologies for the rubbish formatting in the copy/paste

    // ***************************************************
    // // The Calc bit :

    VAR FilterDates =

    FILTER( ALL(Dates), SWITCH( TRUE,

    SelectedTimeFrame = "Week TY",
    Dates[Week] = Reporting_Week_TY &&  Dates[Year] = Reporting_Year_TY,

    SelectedTimeFrame = "Period TY",
    Dates[Week] <= Reporting_Week_TY &&  Dates[Period] = Reporting_Period && Dates[Year] = Reporting_Year_TY,

    SelectedTimeFrame = "YTD TY",
    Dates[Week] <= Reporting_Week_TY && Dates[Year] = Reporting_Year_TY )
    )

    VAR Hold_Calc =
    SUMX ( FilterDates, [Sales Value] )

    RETURN
    IF(ISBLANK(Hold_Calc), 0, Hold_Calc)