Alteryx Designer Desktop Discussions

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

Replace character with specific extension

amitvanage
6 - Meteoroid

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.

2 REPLIES 2
CharlieS
17 - Castor
17 - Castor

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

amitvanage
6 - Meteoroid

Thanks Charlie. This worked.

Labels