cancel
Showing results for 
Search instead for 
Did you mean: 

add leading zero to postal codes

SOLVED
rjohnson123
Meteor

add leading zero to postal codes

I have postal codes from Mexico that are missing 1, sometimes 2, leading zeros.  Each postal code needs to be 5 numerical digits.  How do I add a leading zero for only these records?

4 REPLIES 4
rjohnson123
Meteor

add leading zero to postal codes

I have postal codes from Mexico that are missing 1, sometimes 2, leading zeros.  Each postal code needs to be 5 numerical digits.  How do I add a leading zero for only these records?

Highlighted
JordyMicheal
11 - Bolide

Re: add leading zero to postal codes

Hey There RJohnson!!

 

I built you a little ITERATIVE macro to do the job.

Take a look and let me know if you have any questions

Attachment
Download this attachment
JosephSerpis
17 - Castor

Re: add leading zero to postal codes

Hi @rjohnson123 you would need to convert your field into a string field the numeric field in Alteryx would remove leading zeros. I mocked up a workflow.

Attachment
Download this attachment
PeterS
Alteryx Alumni (Retired)

Re: add leading zero to postal codes

Hi @rjohnson123 

 

The beauty of Alteryx is there are many ways to get the job done.  Here is another option for you that uses the Padleft() function in Alteryx.

 

Like the other posters noted numeric values will not be able to retain the leading zeros.  First convert your ZIP Code to a string with a select tool, make sure that the length of the field is at least 5, then with a Formual Tool use the PadLeft() function.  You will need to specify the field you want to use, the length the final string needs to be, and the value to put in front of the existing sting.  Your function might look like this

 

Padleft([Postcode],5,"0")

 

[Postcode] = Zip code field

5 = length of final string (the total length of a ZIP Code)

"0" = value to put to the left of strings shorter than 5

 

padleft.jpg

 

 Hope this helps!

Peter Stoddard
Manager, Technical Account Management
Alteryx, Inc.


Re: add leading zero to postal codes

Super thank you. This solution has helped me a lot in my challenge in the leading zero's.