ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests Early 2026. Make sure to check your account preferences in my.alteryx.com to make sure you have filled out your security questions. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

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

Simplify IF statement with Contains

hellyars
13 - Pulsar

How can I convert the expression below (that works) to something like this:  

 

if Contains ([FileName],("78","36","13","20","04")) then "X" else "A" endif 

if Contains([FileName],"78") then 'X'
elseif Contains([FileName],"36")  then 'X'
elseif Contains([FileName],"13")  then 'X'
elseif Contains([FileName],"20")  then 'X'
elseif Contains([FileName],"04")  then 'X'
elseif Contains([FileName],"04")  then 'X'
else "A"
endif 

 

1 REPLY 1
Maskell_Rascal
13 - Pulsar

Hey @hellyars 

 

You can use a Regex_CountMatches formula to simplify the If statement. 

 

IF REGEX_CountMatches([FileName], "78|36|13|20|04")=1 THEN "X" ELSE "A" ENDIF

 

 

Maskell_Rascal_0-1611779740016.png

 

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

 

Thanks!

Phil

Labels
Top Solution Authors