Forum Discussion
Date Filter Dax
- Anonymous1 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.
No, you will only ever get a scalar value (single result) out of a SWITCH statement.
So how would I code it without a switch?
- lbendlin1 year agoSuper User
You would add these flags to your calendar table.