5 Replies Latest reply on Mar 15, 2017 11:44 AM by Gerardo Varela

# CONTAINS formula: correctly using

this is my data set

LPST 2017 201 01

LPST 2017 202 01

LPST 2017 401 01

LPST 2017 201 01

LPST 2017 202 01

LPST 2017 202 01

LPST 2017 401 01

LPST 2017 401 01

LPST 2017 202 01

LPST 2017 401 01

LPST 2017 401 02

I would like to group this ID by group with the formula "contains" and say, that

IF I have  ID, which CONTAINs "201" then it is "Fax

IF I have ID which CONTAINs "201" then it is "E-Mail"

This is my formula:

if CONTAINS("LPST 2017 201 01","201") then "Fax"

ELSEIF

CONTAINS("LPST 2017 401 01", "401") then "Email"

ELSEIF

END

And this is my result

I have Fax only. How can I fix it? May be I should try it out with other formula?

If you have any ideas, I would apreciate it.

Thank you!

• ###### 1. Re: CONTAINS formula: correctly using

Hi Dilyana

In this case Tableau is confused with "201" with "2017"

With assuming your data always has space before anda after "201" or "401", the formula should be like this.

[Calculation1]

if CONTAINS([Field Name]," 201 ") then "Fax"

ELSEIF

CONTAINS([Field Name], " 401 ") then "Email"

END

Thanks,

Shin

• ###### 2. Re: CONTAINS formula: correctly using

Hi,

You can use the below formula-

if CONTAINS("LPST 2017 201 01","201 ") then "Fax"

ELSEIF

CONTAINS("LPST 2017 401 01", "401 ") then "Email"

END

Regards,

Irfan

1 of 1 people found this helpful
• ###### 3. Re: CONTAINS formula: correctly using

Wow Shinichiro you're super quick! I was working on a response and by the time I worked it up you had already answered. I hope you don't mind me posting my solution. Here's mine:

It essentially does the same thing.

Regards,

Gerardo

1 of 1 people found this helpful
• ###### 4. Re: CONTAINS formula: correctly using

Gerardo,

I don't mind at all and that always happens,  sometimes I win, sometimes you win.

Yours are also good AS LONG AS the description of "LSPT" part is always "4" digit.

Thanks,.

Shin

1 of 1 people found this helpful
• ###### 5. Re: CONTAINS formula: correctly using

I didn't even think about the description changing.  Thanks Shinichiro!

Regards,

Gerardo