Jump to content
• 0

# Formula for contains

## Question

I have a formula in my table.
CASE WHEN [@field:UserName] = 'Emp'
THEN 'Employee'
ELSE 'Manager'

I wanted to make that if UserName starts with Emp then it is employee otherwise Manager

## Recommended Posts

• 0

Hi,

please try this instead:

CASE WHEN [@field:UserName] LIKE '%Emp'
THEN 'Employee'
ELSE 'Manager'
END

hope this works

-Barbie

##### Share on other sites

• 0

Hello @Barbie,

If you are working with big data, you may want to use the syntax below instead. It works well with your requirement and runs much faster on a database standpoint.

```CASE
WHEN LEFT([@field:usz], 3) = 'Emp'
THEN 'Employee'
ELSE 'Manager'
END```

Hope this helps

-DN31337!

##### Share on other sites

• 0

Hello, just wanted to share this Function Reference that will be definitely a big help on calculations: https://howto.caspio.com/function-reference/

##### Share on other sites

• 0

Thank you for the suggestions. I tried the solutions above.

It seems that Barbie's solution outputs a 'Yes' if the text 'emp' is placed anywhere on the username.  But for DefinitelyNot31337's solution, it outputs a 'Employee' if the username starts with 'emp'.

Solutions are great so I utilized them both. Here is a reference as well: https://howto.caspio.com/datapages/reports/advanced-reporting/calculations-in-forms-and-reports/#:~:text=Birth. Learn more.-,Conditional Cases in Calculated Fields,-You can use

##### Share on other sites

• 0

@trickson you can also try Charindex() for this. Charindex will output the starting point of the string or the character that you are looking for and if that value is greater than 0 that means that there is an Emp in the string.

CASE
WHEN Charindex('Emp',[@field:Name]) > 0
THEN 'Employee'
ELSE 'Manager'
END

##### Share on other sites

• 0

Hello! Another approach is by using the SUBSTRING function to check if the 1st three letters of the field is 'Emp'.

```CASE

WHEN SUBSTRING([@field:UserName], 1, 3) = 'Emp'

THEN 'Employee'

ELSE 'Manager'

END ```

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
• #### Browse

×
• Create New...