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

add leading zero to postal codes

rjohnson123
7 - Meteor

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
JordyMicheal
11 - Bolide

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

JosephSerpis
17 - Castor
17 - Castor

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.

PeterS
Alteryx
Alteryx

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.


csollest_11
5 - Atom

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

 

Labels