Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
blocke
Frequent Visitor

Leading zeroes in zip codes

I am trying to use zip codes to make a heat map but when I import the data from excel, the zeroes infront of certain zip codes are removed. I have tried formatting the zip column as text as suggested in other posts. Are there any other work arounds that I could try?

 

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hey @blocke

 

You can create a calculated column to insert the leading 0's back in. So let's say that you have three zip codes (76342, 08976, and 00323). One has no leading 0's, one has 1, and one has 2. Based on what I'm gathering, when you import them in you are seeing 76342, 8976, 323. You can then create a calculated column to append necessary 0's on front depending on the size of the number like this:

 

RealZipCode = 
SWITCH(
    TRUE(),
    LEN('Table'[ZipCode]) = 5, 'Table'[ZipCode],
    LEN('Table'[ZipCode]) = 4, "0" & 'Table'[ZipCode],
    LEN('Table'[ZipCode]) = 3, "00" & 'Table'[ZipCode]
)

You end up with output that looks like:

 

ZipCode.PNG

 

Hope this helps,

Parker

View solution in original post

6 REPLIES 6
Hollys83
Frequent Visitor

None of the solutions worked for me but adding a prefix did. 

napierjohn
New Member

You can also use this:

= Text.PadStart([Zip],5,"0")
RMGAM
Regular Visitor

=Text.PadStart([ZipCode], 5, "0")

tbutler
Regular Visitor

I know that this was marked as solved, but I also had this issue and fixed it by changing the table column data type definition in Power BI's query editor from int64 to text.

 

Example:  = Table.TransformColumnTypes(Table1_Table,{{"Zip Code", type text}, {"City", type text}, {"County", type text}})

Anonymous
Not applicable

Hey @blocke

 

You can create a calculated column to insert the leading 0's back in. So let's say that you have three zip codes (76342, 08976, and 00323). One has no leading 0's, one has 1, and one has 2. Based on what I'm gathering, when you import them in you are seeing 76342, 8976, 323. You can then create a calculated column to append necessary 0's on front depending on the size of the number like this:

 

RealZipCode = 
SWITCH(
    TRUE(),
    LEN('Table'[ZipCode]) = 5, 'Table'[ZipCode],
    LEN('Table'[ZipCode]) = 4, "0" & 'Table'[ZipCode],
    LEN('Table'[ZipCode]) = 3, "00" & 'Table'[ZipCode]
)

You end up with output that looks like:

 

ZipCode.PNG

 

Hope this helps,

Parker

ZIP = RIGHT("00000" & 'myaddresses'[myzip], 5)

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.