Forum Discussion

monojchakrab's avatar
monojchakrab
Resolver III
4 years ago
Solved

How 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...
  • AlexisOlson's avatar
    AlexisOlson
    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"
    )
  • Ashish_Mathur's avatar
    Ashish_Mathur
    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.