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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Automatically selectin...
Power Apps
Answered

Automatically selecting a choice based on value of string

(0) ShareShare
ReportReport
Posted on by 8

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:
I have the same question (0)
  • v-yueyun-msft Profile Picture
    on at

    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

     

     
  • Hagru Profile Picture
    8 on at

    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

    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
    8 on at

    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.

  • Verified answer
    v-yueyun-msft Profile Picture
    on at

    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
    8 on at

    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.

  • v-yueyun-msft Profile Picture
    on at

    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

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 291 Most Valuable Professional

#2
Kalathiya Profile Picture

Kalathiya 282 Super User 2026 Season 1

#3
VASANTH KUMAR BALMADI Profile Picture

VASANTH KUMAR BALMADI 195

Last 30 days Overall leaderboard