Forum Discussion
Help With SWITCH - d/n support comparing values...
- 1 year ago
Here are valid examples of SWITCH syntax
test1 = var myvalue = 6 RETURN SWITCH(TRUE, myvalue = 5, "Five", myvalue = 6, "Six", myvalue = 8, "Eight", "other")test2 = var myvalue = "S" RETURN SWITCH(TRUE, myvalue = "B", "Brazil", myvalue = "S", "Spain", myvalue = "I", "India", "other")This type of sysntax is invalid SWITCH need a scalar data type (a single value).
The RS case [Status] is a table data typeTest1 = SWITCH(TRUE, 'RS case'[Status] = "OPEN", "Yes", "No" )You can use MIN or MAX return a scalar value but take care with totals. See example
Test2 = SWITCH(TRUE, MAX('RS case'[Status]) = "OPEN", "Yes", "No" )Consider using VAR variables to make your syntax easier to read and test
For example
var mylookup = LOOKUPVALUE('RS Events'[Survey_Date__c],'RS Events'[Id], 'RS Cases'[RS Event ID]) var mycase = MIN('RS Cases'[Status]) var myduedate = MIN(RS Cases'[Due By]) SWITCH( TRUE, // if survey date null & status = Open and Due By is less than today's date, then date dif due by and today's date ISBLANK(mylookup) && myduedate="OPEN" && mycase<TODAY(), DATEDIFF('RS Cases'[Due By], TODAY(),DAY),
This code with perform faster because it only does the lookup once and then holds the anwer as a variable.Rather than your code which does the same lookup for each condition.
You can also view and check each variable to debug and fix the problem.Please click thumbs up and accept solution
Learn how to use SWITCH here
https://learn.microsoft.com/en-us/dax/switch-function-dax
After ther the SWITCH Try insert TRUE, like this
Days Late2 =
SWITCH( TRUE,
// if survey date null & status = Open and Due By is less than today's date, then date dif due by and today's date
ISBLANK(LOOKUPVALUE('RS Events'[Survey_Date__c],'RS Events'[Id], 'RS Cases'[RS Event ID])) && 'RS Cases'[Status]="OPEN" && 'RS Cases'[Due By]<TODAY(),
DATEDIFF('RS Cases'[Due By], TODAY(),DAY),
// if survey date is greater than due by date, then dif b/t survey date and due by date
LOOKUPVALUE('RS Events'[Survey_Date__c],'RS Events'[Id],'RS Cases'[RS Event ID])>'RS Cases'[Due By],
DATEDIFF(LOOKUPVALUE('RS Events'[Survey_Date__c],'RS Events'[Id],'RS Cases'[RS Event ID]),'RS Cases'[Due By],DAY),
// if survey date is null & status is closed & status change date is greater than due by date, then date dif status change date & due by date
ISBLANK(LOOKUPVALUE('RS Events'[Survey_Date__c],'RS Events'[Id], 'RS Cases'[RS Event ID])) && 'RS Cases'[Status]="CLOSED" && 'RS Cases'[Status Change Date]>'RS Cases'[Due By],
DATEDIFF('RS Cases'[Status Change Date],'RS Cases'[Due By],DAY),
"0")
- Txtcher1 year agoHelper V
Sorry, that yielded this error:
Expressions that yield variant data-type cannot be used to define calculated columns