cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Kirsten2
Helper V
Helper V

Help extracting "State" from address field.

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kirsten2
Helper V
Helper V

//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. 

View solution in original post

5 REPLIES 5
v-bofeng-msft
Community Support
Community Support

Hi @Kirsten2 ,

 

Please try:

 

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

 

Best Regards,

Bof

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

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

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. 

Kirsten2
Helper V
Helper V

//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. 

Helpful resources

Announcements

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!      

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Community Roundup: A Look Back at Our Last 10 Tuesday Tips

As we continue to grow and learn together, it's important to reflect on the valuable insights we've shared. For today's #TuesdayTip, we're excited to take a moment to look back at the last 10 tips we've shared in case you missed any or want to revisit them. Thanks for your incredible support for this series--we're so glad it was able to help so many of you navigate your community experience!   Getting Started in the Community An overview of everything you need to know about navigating the community on one page!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Ranks and YOU Have you ever wondered how your fellow community members ascend the ranks within our community? We explain everything about ranks and how to achieve points so you can climb up in the rankings! Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Powering Up Your Community Profile Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile. Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Blogs--A Great Place to Start There's so much you'll discover in the Community Blogs, and we hope you'll check them out today!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Unlocking Community Achievements and Earning Badges Across the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. Check out some details on Community badges--and find out more in the detailed link at the end of the article! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Blogging in the Community Interested in blogging? Everything you need to know on writing blogs in our four communities! Get started blogging across the Power Platform communities today! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Subscriptions & Notifications We don't want you to miss a thing in the community! Read all about how to subscribe to sections of our forums and how to setup your notifications! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Getting Started with Private Messages & Macros Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Community User Groups Learn everything about being part of, starting, or leading a User Group in the Power Platform Community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Update Your Community Profile Today! Keep your community profile up to date which is essential for staying connected and engaged with the community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Thank you for being an integral part of our journey.   Here's to many more Tuesday Tips as we pave the way for a brighter, more connected future! As always, watch the News & Announcements for the next set of tips, coming soon!

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

October 2023: Celebrating New User Groups & Events to Check Out!

It's time for our monthly celebration of new user groups that recently joined our community, along with events happening nearby--or even virtually!  There's so much going on our community, it's a great time to pause and celebrate what is happening in our user groups and in our community this October!   PLEASE WELCOME THESE NEW USER GROUPS: Biz Apps Community User Group - Power Platform Community (microsoft.com)  This user group is dedicated for any community members of all skill levels to learn how to get the most out of their community experience. East Michigan Power Platform User Group - Power Platform Community (microsoft.com)  This is the start of a new community covering eastern Michigan, built around the Power Platform. Biz Apps Community User Group  This user group is dedicated for all community members of all skill levels to learn how to get the most out of their community experience.   EVENTS TO CHECK OUT: IN-PERSON AND ONLINE In-Person: September 2023 Hybrid Philadelphia Dynamics 365 & Power Platform User Group Meet  Dynamics 365 and Power Platform Physical Meetup  Hyderabad Power Platform User Group Meetup - Sept 2023 (In-Person)  Manchester September 2023 In Person Meeting  Virtual: Everything Dataverse, Do you know that Dataverse is more than just a Database! POWER PLATFORM MONTHLY DIGEST- SEPTEMBER Baltic Summit 2023 PL-900 Power Platform Fundamentals Training HR and L&D transformation through Power Platform Dynamics 365 Marketing Experience User Groups - Use Cases and Networking Power Platform and Dual Write from Dynamics 365 F&O Perspective ANZ D365 FinOps Team September 2023 meetup 

Top Solution Authors
Top Kudoed Authors
Users online (4,433)