Forum Discussion

nataliesmiy1357's avatar
1 year ago
Solved

Date Filter Dax

Hello!  I created a dax formula that is the following:   Date Range Filter = VAR TodayDate = TODAY() VAR Past3Months = EDATE(TodayDate, -3) VAR Past6Months = EDATE(TodayDate, -6) VAR Past12Mont...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Thank you lbendlin and Shravan133 

    Hi, nataliesmiy1357 

    When you use >=, your switch function should look like this:

    SWITCH(
        TRUE(),
        'Date'[Date] >= Past12Months, "Past12Months",
        'Date'[Date] >= Past6Months, "Past 6 Months",
        'Date'[Date] >= Past3Months, "Past3Months",
        "All Data"
    )

    Or when you use <=, your switch function should look like this:

    SWITCH(
        TRUE(),
        'Date'[Date] <= Past3Months, "Past3Months",
        'Date'[Date] <= Past6Months, "Past 6 Months",
        'Date'[Date] <= Past12Months, "Past12Months",
        "All Data"
    )

    Let me use the following example to show you why:

    Measure 2 = SWITCH(TRUE(),
     SUM('Table'[Value])<=190,"A",
     SUM('Table'[Value])<=150,"B",
     SUM('Table'[Value])<=90,"C"
    )

    In my case 94 is less than 190 and 150, and its correct level should be B. However, since the switch ends the judgment when the first condition is met, then the line corresponding to 94 is judged to be A.

    When I change it to something like this, I get the correct output.

    Measure 2 = SWITCH(TRUE(),
     SUM('Table'[Value])<=90,"A",
     SUM('Table'[Value])<=150,"B",
     SUM('Table'[Value])<=190,"C"
    )

    I've provided the PBIX file used this time below.

     

     

     

    Best Regards

    Jianpeng Li

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.