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 / Choice with variables
Power Apps
Answered

Choice with variables

(0) ShareShare
ReportReport
Posted on by 3

Good day everyone, building and app where I can select between a test and prod environment, specifically a SharePoint list.. I need to be able to switch between both. I have the following statement but for some reason the item is not searched:

 

prd is of course my selection I have made... 

 

If(prd = "yes", Choices([@'Exceptions'].Status),Choices([@'TestE'].Status))

This does not work and the minute I enter text it does not search for the item.

 

If I just have Choices([@'Exceptions'].Status) this works and the minute I enter text it searches for the item.

 

The choice is an AD people list.   Any help would be appreciated.

Categories:
I have the same question (0)
  • mdevaney Profile Picture
    29,991 Moderator on at

    @ximian 

    Where exactly are you using this code in the app?  Please tell me:

     

    • Which type of control
    • Which property in that control

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @ximian 

    You're not going to be able to switch datasources on a control like that.  Causes unpleasant issues.

     

    As an option, you might consider collection the two lists:

    ClearCollect(colMyList, 
     AddColumns(Choices([@'Exceptions'].Status), "Prod", "Yes")
    );
    
    Collect(colMyList, 
     AddColumns(Choices([@'TestE'].Status), "Prod", "No")
    )

    Then for your item property on the control, use this:

    Filter(colMyList, Prod=prd)

    This will get you closer to what you are looking for and this works well when the datasources have the same signature - you are using "Status" and I am assuming they are pretty much the same.

     

    I hope this is helpful for you.

     

  • ximian Profile Picture
    3 on at

    Hello everyone thank you for the quick response...  Clearly I am new to this and probably did not formulate my question accordingly

     

    My variable is prd and it is set to yes if I want to work on the Production SharePoint list or to no if I want to use the Test SharePoint List. This is at the start of my PowerApp. Then the user fills out a form.

     

    So my idea was to use choice and based on YES or NO select the appropriate list to lookup the users choice

     

    The choice is in a form, and it is made to look up an item that the user selects, in this particular case the field looks up a certain status the user wants to set the field too.

     

     

     

    So would I do the following?
    If(prd = "yes", ClearCollect(colMyList, 
     Choices([@'Exceptions'].Status)
    ), Collect(colMyList, 
     Choices([@'TestE'].Status)
    )
    
    item = colMyList?

     

     

     

     

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @ximian 

    Yes, again, the ability to do that (switching datasources on a control) is not really available in PowerApps.  In "some" cases you can get away with it, but it is generally advised to avoid trying to do so. 

    My suggestion remains as an option - again considering that the signatures of the two lists are identical. 

    ClearCollect(colMyList, 
     AddColumns(Choices([@'Exceptions'].Status), "Prod", "Yes")
    );
    
    Collect(colMyList, 
     AddColumns(Choices([@'TestE'].Status), "Prod", "No")
    )
    Then for your item property on the control, use this:
    Filter(colMyList, Prod=prd)

    The only other option is to have two controls - one with the production list and one with the test list.  Depending on the choice of your variable, you could set the visibility property of the controls accordingly.  It's not a pretty solution.

     

    For doing production and testing design work - you should, in general have an identical environment in test (same list names, columns, types, etc.).  When you are finished testing and ready for production, you can remove your datasources from PowerApps and then add them all back in based on the production site.  If both are identical, your PowerApp will work exactly the same.

     

  • Verified answer
    v-yutliu-msft Profile Picture
    Microsoft Employee on at

    Hi @ximian ,

    Do you want to change data source based on a variable?

    Could you tell me:

    1)where do you want to put this formula?

    2)Are Status in 'Exceptions' list and Status in 'TestE' list both person type?

    Based on your description, I think you want to put this formula in a combo box's Items.

    If so, please do not use this kind of formula with If statement in a combo box's Items.

    Because every time you change data source in combo box, it will reset the combo box.

    You need to choose displayfield and searchfield for it when it is reset.

    When you design the app, you have two data source, so you can not choose displayfield and searchfield for this combo box.

    So the combo box will always display nothing.

    Please only use one data source in one combo box.

     

    What's more, since your field data type is person, I not suggest you save the two fields data in a collection neither.

     

    Based on your demands, I figure out an alternative solution:

    insert two combo boxes, decide the visibility of combo boxes based on the variable.

    For example:

    Insert two combo boxes.

    Set combo box1's Items: 

    Choices([@'Exceptions'].Status)

    set combo box1's Visible:

    If(prd = "yes",true,false)

    set combo box2's Items:

    Choices([@'TestE'].Status)

    set combo box2's Visible:

     

    If(prd = "yes",false,true)

     

    You could put combo box1 and combo box2 in the same position.

    When prd value is "yes", combo box1 will be visible. Otherwise, combo box2 will be visible.

     

     

    Best regards,

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 429 Most Valuable Professional

#2
11manish Profile Picture

11manish 191 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 122 Super User 2026 Season 2

Last 30 days Overall leaderboard