Skip to main content

Notifications

Power Apps - Building Power Apps
Unanswered

Remove selected item from multi select based on another selection in SAME combobox?

(0) ShareShare
ReportReport
Posted on by 829

Hi Folks -

I have a multiselect ComboBox that is multiselect.  There are times when the users can select a value called "Not Applicable" and then submit.  However, I need functionality to remove the "Not Applicable" when there is another value selected. Is this possible?

 

For instance, if "Not Applicable" is selected, then "Value2" is select, I need to remove "Not Applicable" from the selection.

 

Thank you!

  • mdevaney Profile Picture
    mdevaney 29,987 on at
    Re: Remove selected item from multi select based on another selection in SAME combobox?

    @simms7400 

    PowerApps doesn't let us change the combobox options until a change is completed (your desire) nor does it allow us to manipulate the selection of the combobox once made.  I'm afraid all you can do here is give the user some visual cues (highlight the combo border red) or show an error when they select both at once.  You can also write some form validation code to prevent submission.  Of course, these are just general tips.  Hopefully I have answered you question in an easy to understand way.  Unfortunately, I do not see a really good workaround here.

  • simms7400 Profile Picture
    simms7400 829 on at
    Re: Remove selected item from multi select based on another selection in SAME combobox?

    @mdevaney 

     

    I tested the code you gave me (modifying it with my name specifics of course) and its WORKS, however it's just a little bit clunky.  For instance, if user selects "Not Applicable" and then anoher value, the field will get wiped clean but I still need to click on the field, X the "Not Appliable" and then select other value.  My hope was after "Not Applicable" was removed after it met the condition in your code, I wouldn't need to do anything else but select the new values.

     

    Thoughts?

     

    @v-xida-msft 

     

    Hmmm, this loks promising, but my Items property for this box is already set to:

    If( DataCardValue133.Selected.Value="Device",
    	Filter(Sort(DevicePlatformList,Alias, Ascending),Alias<>"Not Applicable"),
    	Sort(DevicePlatformList,Alias, Ascending)
    )

    And since is a multi-select field, my defaultselecteditems property is set to the following:

    Filter(DevicePlatformList, Alias in Split(ThisItem.Device_Platform, ",")).Alias

    How would I leverage your soluction with my above things already in place? Thanks!

  • v-xida-msft Profile Picture
    v-xida-msft on at
    Re: Remove selected item from multi select based on another selection in SAME combobox?

    Hi @simms7400 ,

    I have made a test on my side, please consider take a try with the following workaround:9.JPG

    Set the Items property of the ComboBox to following:

    ["Not Applicable", "Value2", "Value3"]

    Set the OnChange property of the ComboBox to following:

    ClearCollect(TempCollection, ComboBox1.SelectedItems);
    If(
     Last(FirstN(TempCollection, 2)).Value="Value2" && Last(FirstN(TempCollection, 1)).Value="Not Applicable",
     RemoveIf(TempCollection, Value="Not Applicable")
    )

    Set the DefaultSelectedItems property of ComboBox to following:

    ForAll(TempCollection, {Value: Value})

    Please take a try with above solution, check if the issue is solved.

     

    Best regards,

  • simms7400 Profile Picture
    simms7400 829 on at
    Re: Remove selected item from multi select based on another selection in SAME combobox?

    Added this to this to the first line and it seems to work!

     

    "Not Applicable" in CB_Device_Platform.SelectedItems.Alias && CountRows(CB_Device_Platform.SelectedItems.Alias)>=2

    Will test with the users today.  Thank you! I will report back.

  • simms7400 Profile Picture
    simms7400 829 on at
    Re: Remove selected item from multi select based on another selection in SAME combobox?

    @mdevaney  

     

    Thank you for the solution, this is working as you intended it. However, it's not quite what I need.  For instance, a user can select "Not Applicable" from the list of drop downs based on what data element he or she is creating and submit that.  However, if "Not Applicable" + 1 or mor eother values are also picked, I need to REMOVE Not Applicable from the list of selected items so it's not submitted.

     

    Unfortunately, I'm unable to use another field as a control or check to say "If this field is selected, then hide "Not Applicable" from the Combobox...I'm unable to do this.

     

    Can this be modified for my need?

  • mdevaney Profile Picture
    mdevaney 29,987 on at
    Re: Remove selected item from multi select based on another selection in SAME combobox?

    @simms7400 

    In my humble opinion the best way to ensure a valid selection is made would be to prevent the user from making an invalid selection.  For example, suppose you have a collection like this

     

    ClearCollect(
     myCollection,
     {Value: "Option 1"},
     {Value: "Option 2"},
     {Value: "Option 3"},
     {Value: "Not Applicable"}
    );

     

    Now create a new ComboBox with these properties

     

    Items: myCollection
    DisplayFields: ["Value"]

     

    You can prevent the user from selecting Not Applicable when another Option is already selected and vice versa by putting this code in the OnChange property of the ComboBox.

     

     

    If(
     "Not Applicable" in ComboBox1.SelectedItems.Value,
     ClearCollect(myCollection,{Value: "Not Applicable"}),
     If(
     IsEmpty(ComboBox1.SelectedItems.Value),
     ClearCollect(
    myCollection,
    {Value: "Option 1"},
    {Value: "Option 2"},
    {Value: "Option 3"},
    {Value: "Not Applicable"}
    ), Remove(myCollection,{Value: "Not Applicable"}); ) );

     

    Give this method a try for yourself in a Test Application.  I think you'll like it!

     

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

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,343

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,703

Leaderboard