Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Splitting Counties and States and State Code Conversion

I have a column called State/Country and it contains either a country name (e.g. Korea) or a state code (e.g. CA)

What I need to do is to separate those into 2 columns:

Var = State/Country

If length(Var) > 2 then CountryColumn = Var, StateColumn = “ “

Else CountryColumn=USA, StateColumn = decodeStateAbbr (??)

 

My questions: how can I write this in DAX and how can I decode state abbriviation?

 

  • Anonymous not sure wht you mean by decode state abbreviation. here is calculated columns looks like

     

    Country = IF( LEN(Table[Country/State]) > 2, Table[Country/State], "USA" )
    
    State = IF( LEN(Table[Country/State]) > 2, "", Table[Country/State])
    

6 Replies

  • Anonymous not sure wht you mean by decode state abbreviation. here is calculated columns looks like

     

    Country = IF( LEN(Table[Country/State]) > 2, Table[Country/State], "USA" )
    
    State = IF( LEN(Table[Country/State]) > 2, "", Table[Country/State])
    
    • Anonymous's avatar
      Anonymous
      Not applicable

      parry2k 

      Thank you! By decoding I mean converting CA to California, NY to New York, etc. May be I should split the column first and then decode the State?

       

      • parry2k's avatar
        parry2k
        Super User

        Anonymous sure I already did the split for you and from there you can decode to long state name.