Skip to main content
Community site session details

Community site session details

Session Id : +D0lse9SlWjCiRw4xHMMAT
Power Apps - Building Power Apps
Answered

Automatically selecting a choice based on value of string

Like (0) ShareShare
ReportReport
Posted on 18 Jun 2024 12:00:37 by

Hello!

 

I am building a PowerApp that is performing an API call, and the API call is returning a string that is either "left" or "right".

I also have a form in my PowerApp that includes a choice field, with the options "Left" and "Right".

 

I would like to automatically fill the choice with the corresponding value based on what the string says. How can I achieve this?

Categories:
  • v-yueyun-msft Profile Picture
    on 19 Jun 2024 at 09:13:14
    Re: Automatically selecting a choice based on value of string

    Hi , @hagru 

    Please try this:

    If( Proper( varData ) ="Left" , Filter( Choices(Direction_1) , Text(Value) = "Left")  , Filter( Choices(Direction_1) , Text(Value) = "Right") )
     

    Best Regards,

    Yueyun Zhang

  • Hagru Profile Picture
    on 19 Jun 2024 at 08:37:13
    Re: Automatically selecting a choice based on value of string

    Thank you so much @v-yueyun-msft! That did the trick!

    Just a little follow-up question for future reference and learning - are there any way to use the values of the choices instead of the indexes? Using the values makes it a bit easier on the eye.

  • Verified answer
    v-yueyun-msft Profile Picture
    on 19 Jun 2024 at 08:08:42
    Re: Automatically selecting a choice based on value of string

    Hi, @hagru 

    Thanks for your response!Your data source is Dataverse.
    For example , if we Choices Set is like this, the first is "Left", second is "Right":

    vyueyunmsft_0-1718784457930.png

    You can use this code in your DefaultSelectedItems:

    If( Proper( varData ) ="Left" , Index(Choices(Direction_1) ,1) , Index(Choices(Direction_1) ,2) )
     
    You can replce the "varData " to your expression which return the "left" text string api.
     

     

    If this reply can help you , you can click mark this reply as solution (Accept solution) which can help more people, thanks in advance! 

     

    Best Regards,

    Yueyun Zhang

     

     

     
     
  • Hagru Profile Picture
    on 19 Jun 2024 at 07:15:02
    Re: Automatically selecting a choice based on value of string

    Hi @v-yueyun-msft 

     

    I just edited my initial response.

    The Items property is Choices(Direction). The two options are "Left" and "Right", they are both just text.

     

    With your suggestion, it looks like the correct value is selected, but when submitting the form and looking at the table row in Dataverse, the Direction column is empty. The field is a Choice column.

  • v-yueyun-msft Profile Picture
    on 19 Jun 2024 at 07:11:43
    Re: Automatically selecting a choice based on value of string

    Hi , @hagru 

    Thanks for your response! Can you show me your Combo box -items property in your side?

    And do you mean you submit the Form , but the data do not save to your data source? And what's the data type of this field in your data source?

     

    Best Regards,

    Yueyun Zhang

     

  • Hagru Profile Picture
    on 19 Jun 2024 at 07:08:36
    Re: Automatically selecting a choice based on value of string

    Hello @v-yueyun-msft 

     

    That does select the right value in my Combobox, and it looks good, but when submitting the Form, the value is empty in the table row 😕

     

    The choices are also set in the table column, which, so my Items property is Choices(Direction). The two options are "Left" and "Right".

  • v-yueyun-msft Profile Picture
    on 19 Jun 2024 at 01:29:55
    Re: Automatically selecting a choice based on value of string

    Hi  , @hagru 

    You can use this expression in your Combox - DefaultSelectedItems:

    {Value :Proper( "left" ) }
     
    You can replce the "left" to your expression which return the "left" text string api.
    And my Combo box -items property is this:
    ["Left","Right"]
     
     

    If this reply can help you , you can click mark this reply as solution (Accept solution) which can help more people, thanks in advance! 

     

    Best Regards,

    Yueyun Zhang

     

     

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473

Loading complete