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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
kyliemcpoland
New Member

Zip code to place

We have data that contains the 5 digit zip codes. Is there a way to transform these numbers into the name of the city. 

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @kyliemcpoland 

 

Yes, you'll need to create a table that contains the zip codes and the corresponding city names.  Then you can create a relationship between that table and your main data table, and write any measures/create visuals you need.

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

5 REPLIES 5
dufoq3
Super User
Super User

Hi @kyliemcpoland, if you find web page with your_country zip codes - you can do something like this. This is for Slovakia for example:

The code is not so simple, because I had to use Fn_Unzip (the reason is that I've found Slovakian zip codes only zipped version available online).

 

let
    Fn_Unzip =
        (ZIPFile) =>
        let
            Header = BinaryFormat.Record([
                MiscHeader = BinaryFormat.Binary(14),
                BinarySize = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32, ByteOrder.LittleEndian),
                FileSize   = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32, ByteOrder.LittleEndian),
                FileNameLen= BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.LittleEndian),
                ExtrasLen  = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.LittleEndian)    
            ]),
        
            HeaderChoice = BinaryFormat.Choice(
                BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32, ByteOrder.LittleEndian),
                each if _ <> 67324752             // not the IsValid number? then return a dummy formatter
                    then BinaryFormat.Record([IsValid = false, Filename=null, Content=null])
                    else BinaryFormat.Choice(
                            BinaryFormat.Binary(26),      // Header payload - 14+4+4+2+2
                            each BinaryFormat.Record([
                                IsValid  = true,
                                Filename = BinaryFormat.Text(Header(_)[FileNameLen]),
                                Extras   = BinaryFormat.Text(Header(_)[ExtrasLen]),
                                Content  = BinaryFormat.Transform(
                                    BinaryFormat.Binary(Header(_)[BinarySize]),
                                    (x) => try Binary.Buffer(Binary.Decompress(x, Compression.Deflate)) otherwise null
                                )
                                ]),
                                type binary                   // enable streaming
                        )
            ),
        
            ZipFormat = BinaryFormat.List(HeaderChoice, each _[IsValid] = true),
        
            Entries = List.Transform(
                List.RemoveLastN( ZipFormat(ZIPFile), 1),
                (e) => [FileName = e[Filename], Content = e[Content] ]
            )
        in
            Table.FromRecords(Entries),

    SourceWebZipCodes = Web.Contents("https://www.posta.sk/subory/322/psc-obci-a-ulic.zip"),
    Unzipped = Fn_Unzip(SourceWebZipCodes),
    FilteredRows = Table.SelectRows(Unzipped, each ([FileName] = "POBoxy.xlsx")),
    Content = Excel.Workbook(FilteredRows{0}[Content], true),
    ZipCodesTable = Content{[Item="PSČ_POBOXov!_xlnm._FilterDatabase",Kind="DefinedName"]}[Data],
    RenamedColumns1 = Table.RenameColumns(ZipCodesTable,{{"PSČ pre P.O.BOXy", "Zip Code"}}),
    ChangedType = Table.TransformColumnTypes(RenamedColumns1,{{"Zip Code", Int64.Type}}),
    // Table with zip codes I want to transoform to city name.
    SourceZipCodesToDecode = #table(type table[ZIP=Int64.Type], {{96261},{96001},{96233},{90055}}),
    MergedQueries = Table.NestedJoin(SourceZipCodesToDecode, {"ZIP"}, ChangedType, {"Zip Code"}, "ZipCodesWeb", JoinKind.LeftOuter),
    ExpandedZipCodesWeb = Table.ExpandTableColumn(MergedQueries, "ZipCodesWeb", {"Názov pošty"}, {"Názov pošty"}),
    RenamedColumns2 = Table.RenameColumns(ExpandedZipCodesWeb,{{"Názov pošty", "City"}}),
    RemoveSpecialCharsAndNumbers = Table.TransformColumns(RenamedColumns2, {{"City", each Text.FromBinary(Text.ToBinary(Text.Remove(_, {"0".."9"}), 1251), TextEncoding.Ascii), type text}})
in
    RemoveSpecialCharsAndNumbers

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Anonymous
Not applicable

Hi @kyliemcpoland ,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

@Anonymous @Anonymous 

 

How is this accepted answer actually an answer?  Surely my response is better, and a solution.

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

Hi  @PhilipTreacy ,

 

I am sorry, I did make an error mark. I had intended to accept your response as the solution. I will be more careful next time. Thank you for your reminder. Have a good day.

 

Best Regards,

Liu Yang

PhilipTreacy
Super User
Super User

Hi @kyliemcpoland 

 

Yes, you'll need to create a table that contains the zip codes and the corresponding city names.  Then you can create a relationship between that table and your main data table, and write any measures/create visuals you need.

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.