In case you missed the announcement: Alteryx One is here, and so is the Spring Release! Learn more about these new and exciting releases here!

Alteryx Designer Desktop Discussions

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

Using a condition to replace something, but do nothing if the condition does not exists.

maheshkumar7
6 - Meteoroid

Hi - I have a survey that as fields like 

"4 - agree"

"3 - neutral"

"2 - disagree"

"1 - completely disagree" 

and random comments. 

 

I want to replace the first 4 with 4, 3, 2, 1 respectively - but if it not any of those then I just want to keep it as it is. 

 

For example, if it just says "The session was good" I'd just like to leave it like that. 

 

I have tried switch, and tried to use two "replace()" and IF statement, but it does not seem to work. 

2 REPLIES 2
MelGibson
10 - Fireball

Try this - I had a cleanse tool - just to clean it up and then I added formula tool. You can create a new field or you can update the one you have. I named your field Survey that had your input data. 

 IF CONTAINS([SURVEY],'4') AND CONTAINS([SURVEY],'agree') then '4' elseif CONTAINS([SURVEY],'3') AND CONTAINS([SURVEY],'neutral') then '3'
elseif CONTAINS([SURVEY],'2') AND CONTAINS([SURVEY],'disagree') then '2' elseif CONTAINS([SURVEY],'1') AND CONTAINS([SURVEY],'disagree') then '1'
else REGEX_Replace([SURVEY], '"', "") endif 

survey.png

 

CoG
14 - Magnetar

What does your workflow/formula look like? If those values are the only contents of a particular field, then you can use the following in a Multi-Field Formula Tool:

 

IF [_CurrentField_] in ("4 - agree","3 - neutral","2 - disagree","1 - completely disagree")

THEN

LEFT([_CurrentField_],1)

ELSE

[_CurrentField_]

ENDIF

 

More information would be helpful to provide more specific guidance.

 

Hope this helps and Happy Solving!

Labels
Top Solution Authors