Alteryx Designer Desktop Discussions

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

How to add a dash to SOME zip codes only

vmirand
6 - Meteoroid

Hello. I am trying to add a dash to the zip codes with a length of more than 5 NUMERIC characters only. Also, I have zip codes of 6 characters (letters and numbers) that I am not looking to edit. Can somebody please help me with a formula that meets those conditions?

 
Zip codeResult
98604485098604-4850
7993679936
56465426256465-4262
R2X1G7R2X1G7

 

Thank you

2 REPLIES 2
DataNath
17 - Castor

Hey @vmirand, there's a few ways to go about this - here's what I've quickly put together:

 

1717.png

 

Formula expression:

 

IF REGEX_Match([Zip code], '\d{6,}')
THEN REGEX_Replace([Zip code], '(.{5})(.*)', '$1'+'-'+'$2')
ELSE [Zip code]
ENDIF

 

Without RegEx you could use standard functions to do something like:

 

 

IF Length([Zip code]) > 5 AND IsInteger([Zip code])
THEN Left([Zip code], 5) + '-' + Right([Zip code], Length([Zip code])-5)
ELSE [Zip code]
ENDIF

 

 

vmirand
6 - Meteoroid

Thank you much @DataNath ! It worked.

Labels