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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
lipster26
Frequent Visitor

Extract State from text field

Hello,

I'm looking for a solution to extract the 2 characters for States from a free form text field. The 2 characters might be anywhere in the text column. I can also have another table that would contain the states abbreviations to do a lookup. But I'm not sure how to extract the 2 characters from Text column. Thanks for any help.

 

TextDesired Result
2021 NY EXT PMTNY
2017 CEG PA REFUNDPA
LA FRANCHISE TAX PMT RECODING TO ACCOUNT 21156300LA
MS FRANCHISE TAX PMT RECODING TO ACCOUNT 21156300MS
TN FRANCHISE TAX PMT RECODING TO ACCOUNT 21156300TN
CPG-LA2019-20 FRANCHISE TAX PMT RECODINGLA
CPG-MS 2020 FRANCHISE TAX PMT RECODINGMS
CPG-NC 2020 FRANCHISE TAX PMT RECODINGNC
TN FRANCHISE TAX PMT RECODING TO 21156300TN
2017 PA INCOME TAX NOTICE PAYMENTPA
2018 TN REFUNDTN
1 ACCEPTED SOLUTION
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Based on the pattern, I can notice that any two alphabets word which appears first is a state in your strings. You can use following formula in a custom column without needing a lookup table

= List.First(List.Select(Text.SplitAny(Text.Trim(Text.Remove([Text],{"0".."9"})),"  -"),(x)=>Text.Length(x)=2))

 But if any two alphabets word appear first which is not a state name, then you would require a lookup table. This approach is suggested by @artemus

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Based on the pattern, I can notice that any two alphabets word which appears first is a state in your strings. You can use following formula in a custom column without needing a lookup table

= List.First(List.Select(Text.SplitAny(Text.Trim(Text.Remove([Text],{"0".."9"})),"  -"),(x)=>Text.Length(x)=2))

 But if any two alphabets word appear first which is not a state name, then you would require a lookup table. This approach is suggested by @artemus

artemus
Microsoft Employee
Microsoft Employee

Add a custom column that splits the Text into words (add additional word bounderies as needed).

Text.SplitAny([Text], " .,;")

Click the new column and choose "Expand to New Rows"

Perform an inner join with your state table in order to filter it.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.