Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
Register for the upcoming Live Community Q&A Session - and don't forget to submit your questions for @DeanS regarding the future role of analytics here.
SOLVED

Replace character with specific extension

Highlighted
5 - Atom

Hi,

I am new to Alteryx and I have a situation that I have to replace a particular string with a country code.

For e.g We have AAPL.USD, NVDA.USD, BABA.CNY, WUBATZ.CNY. All the cells that have extension needs to be replaced by "US" and all the cells that have extension .CNY needs to be replaced with "CN".

 

I am currently using the following formula but it seems to not work correctly.

 

IF Contains([Code],"*.USD") THEN "US" ELSEIF Contains([Code],"*.CNY") THEN "CN" ELSE [Code] ENDIF

 

Please let me know if there is any better way to resolve this.

Highlighted
Alteryx Certified Partner
Alteryx Certified Partner

The Contains( function will only return 'true'/'false' when applied to a Boolean field. In the case of a string field, the 'true' condition is expressed as '-1'. Try this formula:

 

IF Contains([Code],".USD")=-1 THEN "US"
ELSEIF Contains([Code],".CNY")=-1 THEN "CN"
ELSE [Code] ENDIF

Highlighted
5 - Atom

Thanks Charlie. This worked.

Labels