Forum Discussion
SWITCH statement in DAX using a "between this value and this value" as a filter?
- 10 years ago
The SWITCH statement allows comparisons with constants only. You need to use an IF statement. For a calculated column, this is an example:
Pop Classification =
IF(Population[Pop] >= 1000 && Population[Pop] <= 25000,
1,
IF(Population[Pop] >= 25001 && Population[Pop] <= 50000,
2,
0)
) - 10 years ago
I copied exactly what you posted and it worked for me. Make sure your data is of type Decimal and not Text.
- 10 years ago
Figured it out... or at least partially... it's summarizing data when it shouldn't so it's adding it somewhere.
So all of your suggestions have helped! :) Thank you!!
- 10 years ago
I was about to tell you that. Check the table fields for an aggregate function.
Hmm.... I'm glad it's working.. .at least for someone. :)
Here's what it's doing to mine...
Figured it out... or at least partially... it's summarizing data when it shouldn't so it's adding it somewhere.
So all of your suggestions have helped! :) Thank you!!
- asocorro10 years ago
Skilled Sharer
I was about to tell you that. Check the table fields for an aggregate function.
- greggyb10 years ago
Resident Rockstar
SWITCH() can only compare to a constant, this is true, but you can still utilize it to avoid nested IF()s for a cleaner syntax and easier modification.
Simply match against the constant TRUE(), then each of your tests (which are Boolean expressions anyway) are tested for equality with TRUE():
// DAX // SWITCH() instead of nested IF() - works in measure, column, or table SwitchTrue = SWITCH( TRUE() ,<boolean expression>, <result if true> ,<boolean expression>, <result if true> , ..., ... ,<else condition - no trues above> )- PowerBINewbie_18 years ago
Helper I
Hi,
Does this work with dates? For example:
SWITCH(
TRUE()
,[SharePointColumnA]="",0
,[SharePointColumnD]="", CALCULATE(SUM(DateTable[WORKDAY], DATESBETWEEN (DateTable[Date], 'SharePointList'[SharePoint ColumnA], Format(TODAY(), "mm/dd/yyyy")
, CALCULATE(SUM(DateTable[WORKDAY], DATESBETWEEN (DateTable[Date], 'SharePointList'[SharePoint ColumnA],'SharePointList'[SharePoint ColumnD]))
I'm simply trying to find the networkdays/business days between two dates when the end user supplies those two dates. Otherwise, if they don't supply the beginning date which is the SharePoint Column A date, then set the value in that row to 0. and if they only supply an end date, then take the date that was supplied in the beginning date and give me the total value of the business days between that date and today.