Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

How to make two Replace function in one expression

adrian_esteban
5 - Atom
I'm trying to replace two different target in one expression. I'm using Action tool >> Update Raw XML with Formula.
4 REPLIES 4
MacRo
Alteryx
Alteryx

Hi Adrian, you can do this by wrapping one Replace() function around another, like this:

 

Replace(Replace([string_field],"Target1","Replacement1"),"Target2","Replacement2")
MatthieuArzel
7 - Meteor

This is not very eleguant.

I'm new to this game, but isn't there a function (in PHP there's the function strtr) allowing an array where a key will be replace by a corresponding value ?

This solution work for 2 or 3 nested replace. I have 12 replace to do in order to solve a baldy formated month problem.

MarqueeCrew
20 - Arcturus
20 - Arcturus

@MacRo's advice is the way that I typically perform these nested replacements.  However, you can use a FIND REPLACE tool and cause:  Mark Frisch to become Marquee Crew if the FIND REPLACE tool reads a source that converts Mark to Marquee and Frisch to Crew.

 

Please take a look at the attached example workflow.

 

Cheers,


Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
MatthieuArzel
7 - Meteor

The replacement tool is really handy when you need to search and replace in your fields values. I love to do this.

 

The thing is i'm using a dyanmic rename action in order to clean my columns name (before using a big transposition action).

Dynamic rename doesn't allow me to input the search and replace action flow. 

 

I was looking for a solution using only formula fonctions inside dyanmic rename.

 

DateTimeParse(
REGEX_Replace(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
[_CURRENTFIELD_]
, "janv", "01")
, "fév", "02")
, "mars", "03")
, "avr", "04")
, "mai", "05")
, "juin", "06")
, "juil", "07")
, "août", "08")
, "sept", "09")
, "oct", "10")
, "nov", "11")
, "déc", "12")
, "^Diary Time (\d+)\s(\d+).?\s(\d+)$", "\3-\2-\1"), 
"%Y-%m-%d")

 

If you have any advise for something more clean, I am very interested.

 

Labels