Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

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

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?

Alteryx Certified Partner

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

Alteryx Certified Partner

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.


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




[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




 Hope this helps!