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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Ramaskriget
New Member

Convert US states to "USA"

Hello there,

 

I have a dataset with tweets from all over the world. I would like to classify those people who gave a US state as their location, as living in the USA. So in short, all the rows that contains a 2 digit state code should be converted to "USA". I could do this manually, but I will need the function in the future as well, so that's a lot of work. 

 

How can I do this?

 

Thanks in advance. 

1 ACCEPTED SOLUTION

@Ramaskriget

 

Please see attached file

 

USA.png


Regards
Zubair

Please try my custom visuals

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

HI @Ramaskriget

 

Try this. First create a separate Table with all the States in USA. Lets call it US_States

From the Home Tab>>New Data....Copy paste the data below

 

NameCode
AlabamaAL
 AlaskaAK
 ArizonaAZ
 ArkansasAR
 CaliforniaCA
 ColoradoCO
 ConnecticutCT
 DelawareDE
 FloridaFL
 GeorgiaGA
 HawaiiHI
 IdahoID
 IllinoisIL
 IndianaIN
 IowaIA
 KansasKS
 Kentucky[E]KY
 LouisianaLA
 MaineME
 MarylandMD
 Massachusetts[E]MA
 MichiganMI
 MinnesotaMN
 MississippiMS
 MissouriMO
 MontanaMT
 NebraskaNE
 NevadaNV
 New HampshireNH
 New JerseyNJ
 New MexicoNM
 New YorkNY
 North CarolinaNC
  North DakotaND
 OhioOH
 OklahomaOK
 OregonOR
 Pennsylvania[E]PA
 Rhode Island[F]RI
 South CarolinaSC
 South DakotaSD
 TennesseeTN
 TexasTX
 UtahUT
 VermontVT
 Virginia[E]VA
 WashingtonWA
 West VirginiaWV
 WisconsinWI
 WyomingWY

 

Then you can add a calculated column in your Main Table to check if the State is a USA state or not

 

Column =
IF ( CONTAINS ( US_States, US_States[Code], TableName[Code] ), "USA", "Others" )

 


Regards
Zubair

Please try my custom visuals

@Ramaskriget

 

Please see attached file

 

USA.png


Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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