web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Help extracting "State...
Power Apps
Answered

Help extracting "State" from address field.

(0) ShareShare
ReportReport
Posted on by 383

Update:

 Now I just need help extracting the State from an address field.

 

I want it to work for the following addresses:

 

183 Holly St., Hollywood, CA 92545

408 Tree St., Cherry Hill, New Jersey 22545

 

So in other words I need it to work for when state and cities can be two words.

 

//State

Trim(Substitute(Match(TextInput3_17Address.Text,",\s*([A-Za-z\s]+)\s").FullMatch,", ",""))

 

The above code for state doesn't work all the time. It doesn't work when the city is two words. The state name captures part of the city name then. Otherwise it's correct. So I tried the following pattern to include digits at the end using Regex, but I need to figure out how to take out the digit at the end afterwards. I am not the best at Regex and strings. 

 

Substitute(Match(TextInput3_17Address.Text,",\s*([A-Za-z\s]+)\s\d").FullMatch,", ","")

 

This produces, like "CA 2" the state, plus the first digit. Does anyone know how I can take off the last character? After that I will just use the Trim() function to get rid of the space. 

 

 

 

 

 

 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Original Post:

I want the default property of a new field to have conditional logic that incorporates parts of a shipping address.

 

So if the field value (DataCardValue158) is "No" then will be "TextName" with City/State of the shipping address. Otherwise it will show the street physical address part. 

 

The shipping address field is in the following format:

 

Street Address, City, State Zip

 

First attempt without inputting the City/State:

If(DataCardValue158.Selected.Value = "No", "TextName City/State",

//Input street address

Left(TextInput3_17Address,Find(",",TextInput3_17Address)-1))

 

This has no errors and works!

 

But I having trouble figuring out how to input the City/State of the shipping address for that new field. 

 

I tried the following:

 

If(DataCardValue158.Selected.Value = "No",

"TextName "&

//Input City

First( Split( Last( Split(TextInput3_17Address, "," ) ).Result, "," ) ).Result

&"/"&

//Input State

Left(

Right(TextInput3_17Address,Find(",",TextInput3_17Address)-1), //Takes City Zip

Find(" ",Right(TextInput3_17Address,Find(",",TextInput3_17Address)-1)-1)), //Just takes City

//Input street address

Left(TextInput3_17Address,Find(",",TextInput3_17Address)-1))

 

I am not getting an error for the State when test out separately, but it doesn't do anything. It doesn't output the State.

And I get an error with the City part:

 

The function 'Split' has some invalid arguments. 

Name isn't valid. 'Result' isn't recognized. 

 

I need help with the City/State part. 

 

Thanks for the help!

 

Categories:
I have the same question (0)
  • v-bofeng-msft Profile Picture
    Microsoft Employee on at

    Hi @Kirsten2 ,

     

    Please try:

     

    First( Split( Last( Split(TextInput3_17Address.Text, "," ) ).Result, "," ) ).Result

     

    Best Regards,

    Bof

  • Kirsten2 Profile Picture
    383 on at

    Thanks! I am still getting an error for that portion. It's the same error:

     

    The function 'Split' has some invalid arguments.

    Name isn't valid. 'Result' isn't recognized.

     

    I was trying to follow the example from below where they use 'Result', but I do not understand what that is? Does that need to be defined elsewhere? Many thanks for your help.

     

    Split function in Power Apps - Power Platform | Microsoft Learn

  • Kirsten2 Profile Picture
    383 on at

    I tried changing the Result to Value, which now shows no errors, but I am not getting city (my intended result), but I am getting State Zip at the end of the string. So I still need help.

     

    First( Split( Last( Split(TextInput3_17Address.Text, "," ) ).Value, "," ) ).Value

     

    I want produce "City/State" from a shipping address field. The shipping address field is in the following format:

     

    Street Address, City, State Zip

  • Kirsten2 Profile Picture
    383 on at

    I am now using regex with Power Apps to extract the city and state. 

    //City

    Substitute(Substitute(Match(TextInput3_17Address.Text,",\s*([^,]+),").FullMatch,", ",""),",","")

    //State

    Trim(Substitute(Match(TextInput3_17Address.Text,",\s*([A-Za-z\s]+)\s").FullMatch,", ",""))

     

    City works! But the State part is not working for all cases.

     

    I want it to work for the following addresses:

     

    183 Holly St., Hollywood, CA 92545

    408 Tree St., Cherry Hill, New Jersey 22545

     

    So in other words I need it to work for when state and cities can be two words.

     

    The above code for state doesn't work all the time. It doesn't work when the city is two words. The state name captures part of the city name then. Otherwise it's correct. So I tried the following pattern to include digits at the end, but I need to figure out how to take out the digit at the end afterwards.

     

    Substitute(Match(TextInput3_17Address.Text,",\s*([A-Za-z\s]+)\s\d").FullMatch,", ","")

     

    I am not the best at Regex and strings. 

  • Verified answer
    Kirsten2 Profile Picture
    383 on at

    //City

    Substitute(Substitute(Match(TextInput3_17Address.Text,",\s*([^,]+),").FullMatch,", ",""),",","")

     

    //State

    Trim(Substitute(Left(Match(TextInput3_17Address.Text,",\s*([A-Za-z\s]+)\s\d").FullMatch,Len(Match(TextInput3_17Address.Text,",\s*([A-Za-z\s]+)\s\d").FullMatch)-1),", ",""))

     

    This works for me. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 392 Most Valuable Professional

#2
11manish Profile Picture

11manish 136 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 109 Super User 2026 Season 2

Last 30 days Overall leaderboard