Forum Discussion
monojchakrab
Resolver III
4 years agoHow to use the Switch function to look for strings
Hey All, I am looking to use the SWITCH function to search thru' a string and then if the string is found, to return the required value. The code is as follows : Active =
SWITCH('summary table...
- 4 years ago
Putting in an OR isn't a problem.
SWITCH ( TRUE (), CONTAINSSTRING ( [Title], "calorie control" ) || CONTAINSSTRING ( [Title], "cook & bake" ) , "Sucralose", CONTAINSSTRING ( [Title], "natural" ) , "Stevia", CONTAINSSTRING ( [Title], "sugar control" ) , "Aspertame" )But this isn't really any different than without the OR.
SWITCH ( TRUE (), CONTAINSSTRING ( [Title], "calorie control" ), "Sucralose", CONTAINSSTRING ( [Title], "cook & bake" ) , "Sucralose", CONTAINSSTRING ( [Title], "natural" ) , "Stevia", CONTAINSSTRING ( [Title], "sugar control" ) , "Aspertame" ) - 4 years ago
Hi,
This calculated column formula works
=LOOKUPVALUE(search_terms[Result],search_terms[Search string],FIRSTNONBLANK(FILTER(VALUES(search_terms[Search string]),SEARCH(search_terms[Search string],Data[Title],1,0)),1))The search terms table looks like this
Search stringResult
Calorie control Sucralose Cook & bake Sucralose natural Stevia sugar control Aspertame Hope this helps.
- 4 years ago
The SWITCH function returns the first result that matches the first argument (in this case, TRUE). So, in this pattern, it returns the result following the first test that evaluates as being true.
More detail here:
https://p3adaptive.com/2015/03/the-diabolical-genius-of-switch-true/
Ashish_Mathur
Super User
4 years agoHi,
This calculated column formula works
=LOOKUPVALUE(search_terms[Result],search_terms[Search string],FIRSTNONBLANK(FILTER(VALUES(search_terms[Search string]),SEARCH(search_terms[Search string],Data[Title],1,0)),1))
The search terms table looks like this
Search stringResult
| Calorie control | Sucralose |
| Cook & bake | Sucralose |
| natural | Stevia |
| sugar control | Aspertame |
Hope this helps.
monojchakrab
Resolver III
4 years agoVery interesting solution Ashish_Mathur .
Will check this out
- Ashish_Mathur4 years ago
Super User
Thank you.