Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Automatically selecting a choice based on value of string

(0) ShareShare
ReportReport
Posted on 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 at
    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 at
    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 at
    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 at
    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 at
    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 at
    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 at
    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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,524 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,906 Most Valuable Professional

Leaderboard