Skip to main content
Solved

SWITCH formula If

  • December 28, 2021
  • 4 replies
  • 41 views

Forum|alt.badge.img+11

I’m trying to create a SWITCH formula checking for specific text within a field.
For instance, if there is a field with a bunch of random numbers and then a name, I want to check for the name in that field, not match the entirety of the text in the field.

Best answer by Justin_Barrett

Assuming that there’s nothing after the person’s name that needs to be omitted/ignored, this formula that uses a regular expression to extract only the name will work:

IF(
    Source,
    SWITCH(
        REGEX_EXTRACT(Source, "[^\\d]*$"),
        "Bob", "Bob's output",
        "Jake", "Jake's output",
        "Arnold", "Arnold's output"
    )
)

If the source material is more complex, could you share a sample?

4 replies

Justin_Barrett
Forum|alt.badge.img+21
  • Inspiring
  • 4647 replies
  • Answer
  • December 28, 2021

Assuming that there’s nothing after the person’s name that needs to be omitted/ignored, this formula that uses a regular expression to extract only the name will work:

IF(
    Source,
    SWITCH(
        REGEX_EXTRACT(Source, "[^\\d]*$"),
        "Bob", "Bob's output",
        "Jake", "Jake's output",
        "Arnold", "Arnold's output"
    )
)

If the source material is more complex, could you share a sample?


Forum|alt.badge.img+11
  • Author
  • Inspiring
  • 12 replies
  • December 29, 2021

Worked great. Thank you.


Forum|alt.badge.img+11
  • Author
  • Inspiring
  • 12 replies
  • March 1, 2024

Assuming that there’s nothing after the person’s name that needs to be omitted/ignored, this formula that uses a regular expression to extract only the name will work:

IF(
    Source,
    SWITCH(
        REGEX_EXTRACT(Source, "[^\\d]*$"),
        "Bob", "Bob's output",
        "Jake", "Jake's output",
        "Arnold", "Arnold's output"
    )
)

If the source material is more complex, could you share a sample?


Hi Justin, you helped me out with this previously.  The source material this year is formatted slightly differently, and I can't seem to get it to work.  Here's an example of the source:

63101156321; 05945; 5574; ; ; 5574COMBS,GORDON

And I would like the formula to output "Gordon"

In addition what does the [^\\d]*$ do?

 

Thanks


Forum|alt.badge.img+11
  • Author
  • Inspiring
  • 12 replies
  • March 1, 2024

I got it working.  In my attempts I must have mis-typed something which mistakenly led me to believe my solution didn't work.  Thanks again!