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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
khalidmadih
Frequent Visitor

How to convert State name to State Abbreviation

Using a power BI script for creating a calculated column, how can we convert a State Name Table into a State Abbreviation?

3 REPLIES 3
chrisu
Responsive Resident
Responsive Resident

State Abbreivation  SWITCH (
    [State Name],
    "Alaska""AK",
    "Alabama""AL",
    "Arkansas""AR",
    "Arizona""AZ",
    "California""CA",
    "Colorado""CO",
    "Connecticut""CT",
    "Delaware""DE",
    "Florida""FL",
    "Georgia""GA",
    "Hawaii""HI",
    "Iowa""IA",
    "Idaho""ID",
    "Illinois""IL",
    "Indiana""IN",
    "Kansas""KS",
    "Kentucky""KY",
    "Louisiana""LA",
    "Massachusetts""MA",
    "Maryland""MD",
    "Maine""ME",
    "Michigan""MI",
    "Minnesota""MN",
    "Missouri""MO",
    "Mississippi""MS",
    "Montana""MT",
    "North Carolina""NC",
    "North Dakota""ND",
    "Nebraska""NE",
    "New Hampshire""NH",
    "New Jersey""NJ",
    "New Mexico""NM",
    "Nevada""NV",
    "New York""NY",
    "Ohio""OH",
    "Oklahoma""OK",
    "Oregon""OR",
    "Pennsylvania""PA",
    "Rhode Island""RI",
    "South Carolina""SC",
    "South Dakota""SD",
    "Tennessee""TN",
    "Texas""TX",
    "Utah""UT",
    "Virginia""VA",
    "Vermont""VT",
    "Washington""WA",
    "Wisconsin""WI",
    "West Virginia""WV",
    "Wyoming""WY",
    "District of Columbia""DC",
    "State not found message"
)

Assuming the state names are of type text you could be crazy and do the below: (NOTE this takes postal Codes to full names) 
State = SWITCH('Master Table'[Item State], "AL", "Alabama", "AK", "Alaska", "AZ", "Arizona", "AR", "Arkansas"
, "CA", "California", "CO", "Colorado", "CT", "Connecticut", "DE", "Delaware"
, "FL", "Florida", "GA", "Georgia","HI", "Hawaii", "ID", "Idaho", "IL", "Illinois", "IN", "Indiana", "IA", "Iowa", "KS", "Kansas"
, "KY", "Kentucky", "LA", "Louisiana", "ME", "Maine", "MD", "Maryland", "MA", "Massachusetts", "MI", "Michigan", "MN", "Minnesota"
, "MS", "Mississippi", "MO", "Missouri", "MT", "Montana", "NE", "Nebraska", "NV", "Nevada", "NH", "New Hampshire", "NJ", "New Jersey"
, "NM", "New Mexico", "NY", "New York", "NC", "North Carolina", "ND", "North Dakota", "OH", "Ohio", "OK", "Oklahoma", "PA", "Pennsylvania"
, "OR", "Oregon", "RI", "Rhode Island", "SC", "South Carolina", "SD", "South Dakota", "TN", "Tennessee", "UT", "Utah", "VT", "Vermont", "VA", "Virginia"
, "WA", "Washington", "WV", "West Virginia", "WI", "Wisconsin", "WY", "Wyoming","TX", "Texas","DC", "District of Columbia", "GU", "Guam", "PR", "Puerto Rico", "VI", "Virgin Islands",
"Unknown State" )

The above would go from state abbreviations to state name, all you need to do is reverse the arguments, it does work

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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