Alteryx Designer Desktop Discussions

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

Replace 2nd instance of a string with another string based on a condition

Hi - Need help!! I have a series of strings as input with each line item assigned a different value as follows: 

InputValue
A_UVWXYZ 1A_CH1
A_VWXYZ 1A_CHD2
A_WXYZ 1A_CHDH3
A_TWXYZ 1A_CHDHH4
A_XYZAB 1A_CK5

 

And I need the output as follows: 

 

Output
A_UVWXYZ 1A_CH
A_VWXYZ 1B_CHD
A_WXYZ 1C_CHDH
A_TWXYZ 1D_CHDHH
A_XYZAB 1E_CK


Basically, I am looking to replace the every second instance (ONLY) of "A_" based on the assigned value as per the following conditions:

if value = 2, replace second instance of "A_" with "B_"

if value = 3, replace second instance of "A_" with "C_"

if value = 4, replace second instance of "A_" with "D_"

if value = 5, replace second instance of "A_" with "E_"

else "A_"

 

It is quite easy to do in excel with the "Substitute" and nested "IF" functions but I am not able to figure out the logic in Alteryx. Any help is greatly appreciated. 

 

Thank you!

3 RESPUESTAS 3
bhrmitra
Bola de fuego

Hi  

 

You can achieve it using a single formula tool.

 

1.png

 

If this solves your issue please mark the answer as correct and also hit the like button, if not let me know! I've attached my workflow for you to download if needed.

 

Thanks,

Abhra Mitra

Hi @bhrmitra, 


Thank you this is really helpful. However and I apologize I should have made it clear in the question, not all the inputs will have the substring "1A_" at 6th position. To elaborate please find the few input examples below: 

 

InputValue
A_UVWXYZ 1A_CH1
A_VWXYZ 1A_CHD2
A_WXYZ 1A_CHDH3
A_TUVWXYZ 1A_CHDHH4
A_XYZAB 1A_C5

 

I have updated my question with this as well, in case you need to reference the output. 

 

Thank you!

bhrmitra
Bola de fuego

Hi,

 

Change the formula to REGEX_Replace([Input], "\d\u", Left(GetWord([Input], 1), 1) + [Character])  it should work.

 

2.png

If this solves your issue please mark the answer as correct and also hit the like button, if not let me know! I've attached my workflow for you to download if needed.

 

Thanks!

Etiquetas