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
Thank you so much for the detailed response. I can't test this until Monday but I am marking your response as a solution as I am sure it is.
And thank you for the advice about variables. I use that lookup statement in another measure. I am going to revise the measure using a variable.
Quick question about the variable example you posted: In the DATEDIFF function you used the table/field name instead of the variable. Is it not possible to use the variable in that portion of the statement?