Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

How do I write the formula to look for more than one value in a text string

sonseeahray
8 - Asteroid

Not finding this answer in the discussions...

 

How do I write the formula to use in the formula tool to look for more than one value in a string with in an IF AND statement?

 

This is what I have:

[MP]="HC" && [ADJ]!=0 && [PrevA]=0 && [PAYS]!=0 && CONTAINS([DESC],"TIME")
then ...

 

What I need is to look for "TIME" OR "DISTANCE" in the [DESC] field...

5 REPLIES 5
Jonathan-Sherman
15 - Aurora
15 - Aurora

You'd need to change your formula to:

 

IF [MP]="HC" && [ADJ]!=0 && [PrevA]=0 && [PAYS]!=0 && CONTAINS([DESC],"TIME")

OR [MP]="HC" && [ADJ]!=0 && [PrevA]=0 && [PAYS]!=0 && CONTAINS([DESC],"DISTANCE")

THEN X

ELSE X

ENDIF

 

If this solves your issue please mark the answer as correct, if not let me know!

 

Regards,

Jonathan

 

LukeG
Alteryx Alumni (Retired)

@sonseeahray 

 

Good question. The formula below will identify whether or not the field contains both "TIME" and "DISTANCE".

If contains([DESC], "TIME") AND contains([DESC], "DISTANCE")
Then "True"
Else "False"
Endif

 

If you would like to determine whether or not it has at least one of the two, the following formula will work.

If contains([DESC], "TIME") OR contains([DESC], "DISTANCE")
Then "True"
Else "False"
Endif

 

Let me know if there are any questions. If I misunderstood the task, please let me know and I will provide additional assistance. 

danilang
19 - Altair
19 - Altair

Hi @sonseeahray 

 

Shorter than @Jonathan-Sherman's version, but logically equivalent.  Note the extra brackets in bold.  

 

IF [MP]="HC" && [ADJ]!=0 && [PrevA]=0 && [PAYS]!=0 && ( CONTAINS([DESC],"TIME") OR CONTAINS([DESC],"DISTANCE") )

THEN X

ELSE X

ENDIF

 

Dan

Jonathan-Sherman
15 - Aurora
15 - Aurora

I did wonder about brackets but have never seen them used! Thanks @danilang, learn something new everyday!

sonseeahray
8 - Asteroid

Thank you @danilang! That is what I needed!

Labels