Forum Discussion

ethinix's avatar
ethinix
Copper Contributor
Dec 24, 2023

Same City Names in different States

I have attached a sample file. Column A contains the cities. Some of them have same city names but their state names are different(column M). I want to add State abbreviation (Column N) to only those cities which are duplicates. For Example if AKRON city is present in Colorado and Indiana, I want Akron Colorado to be Named as AKRON-CO and Akron Indiana to be named as AKRON-IN.

Any help would be greatly appreciated.

6 Replies

  • Lorenzo's avatar
    Lorenzo
    Silver Contributor

    ethinix 

     

    A Power Query option attached

    let
        Source = Table,
        GroupedRows = Table.Group(Source, {"PHYSICAL CITY"},
            {"DATA", each
                Table.AddColumn(_, "PHYSICAL CITY-STATE", (o)=>
                  if Table.RowCount(_) > 1 then Text.Combine({o[PHYSICAL CITY], o[PHYSICAL STATE]}, "-") else null
                ),
                type table
            }
        ),
        CombineTables = Table.Combine(GroupedRows[DATA])
    in
        CombineTables
    • ethinix's avatar
      ethinix
      Copper Contributor
      Thank you so much. Appreciate your help.
      Also kindly let me know if there is anyway, the sheet can fetch Lattitude, Longitude, County and County FIPS from any external source like Google Maps. The file contains the same Lat, Long, County and County info for all the duplicate cities irrespective of the states they are in. Just wondering if this is possible, rather than editing them manually.
      • ethinix's avatar
        ethinix
        Copper Contributor
        I was able to figure this out using Google's Geo Coding. Please ignore the above message. Thanks
    • ethinix's avatar
      ethinix
      Copper Contributor
      Thank you so much. Appreciate your help.

Resources