Forum Discussion
khalidmadih
10 years agoFrequent 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?
MarkCo
7 years agoRegular Visitor
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" )
MarkCo
7 years agoRegular Visitor
The above would go from state abbreviations to state name, all you need to do is reverse the arguments, it does work