community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

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

Replace Last Instance of Character in String

Highlighted
Atom

Hello All,

 

I am working with a set of data that I need to concatenate into one field in the form of a sentence - I have been successfully able to concatenate this data using formulas, but I am running into an issue with one of our formatting requirements. The data elements must be separated out by commas for the most part, except for the last delimiter which must take the form of " and ". Please see below for examples of what I have and what I need.

 

Ex. Current - bank account number,credit card number,address

 

Ex. Needed - bank account number,credit card number and address.

 

I had the idea to attempt to use the below formula in the formula tool to achieve this (where "Summary" is my concatenated field, but I am receiving the below error when i try this. Any help would be greatly appreciated!

 

Formula : Left([Summary], Length([Summary]-FindString(ReverseString([Summary]),","))+" and "+Right([Summary], Length([Summary]-FindString([Summary], " and "))))

 

Error: "Formula: invalid type in subtraction operator"

Alteryx Certified Partner
Alteryx Certified Partner

@gumbi,

 

Here's a quick solve:

 

REGEX_Replace([Field1], "(.*),(.*)", '$1 and $2')

group 1 is everything before last comma

group 2 is everything after last comma

 

Cheers,

 

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and reboot. Order shall return.
Atom

Thanks Mark! Worked perfectly.

Labels