Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.

IF Contains

Highlighted
5 - Atom

Hi ,

 

with contains does it work for part of the string like 

example in the column it got  Asset[343435] or Asset[343432] or Asset[1209]

can I use the formula as 

IF CONTAINS([COLUMN], "Asset[]") 

THEN

"CORRECT"

ELSE

"INCORRECT"

END

 

 

Highlighted
Alteryx Certified Partner
Alteryx Certified Partner

Hello @ashac ,

 

you could use also the formula StartsWith for that matter.

 

IF StartsWith ([COLUMN], 'Asset') THEN "CORRECT" ELSE "INCORRECT" ENDIF

 

Kind regards

Highlighted
Alteryx Certified Partner

Hi @ashac,

 

No that would not work because CONTAINS will only work for things that match everything within the quotation marks.

 

For this situation, you can either just use:

 

CONTAINS([COLUMN], "Asset[") 

Alternatively, a smarter better solution would be use to REGEX.

 

Use the formula below for your solution.

 

IF REGEX_Match([COLUMN], "Asset\[\d+\]")

THEN

"CORRECT"

ELSE

"INCORRECT"

ENDIF

What the REGEX does is that it looks for anything that has "Asset[", then any number of numbers, then closed with "]".

 

Let me know if this helps with your issue.

 

Thanks,

Josh

Alteryx Certified Partner
Alteryx Certified Partner

Another option would be using regex match

 

IF REGEX_Match([Field1], 'Asset\[\d*\]') THEN "CORRECT" ELSE "INCORRECT" END

 

Regards

Labels