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 / forall selected items ...
Power Apps
Unanswered

forall selected items in combobox

(0) ShareShare
ReportReport
Posted on by 5,836 Moderator

Can you use a ForAll to perform an action for each item in a multi-select combobox?

 

@RandyHayes 

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @JR-BejeweledOne 

    Depends on the Action!  What are you trying to achieve?

  • JR-BejeweledOne Profile Picture
    5,836 Moderator on at

    I need to collect data from other fields to create an individual (duplicate) record in a temp collection for each Region in the combobox.   The only difference in each item will be the Region.   There are other processes that are going to be using this temp collection later in the app.

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

    @JR-BejeweledOne 

    Personally, I would just reference the combobox throughout the app instead of another collection.  Your combobox already has the table of data that you need.

     

    Beyond that, if for some reason you need a heavy-weight collection, then you can look at something along this line:

     

    Collect(yourcollection,
     ForAll(
     yourComboBox.SelectedItems,
     {some record}
     )
    )

     

    Now, if that means looking up some other value in another datasource, then:

    Collect(yourcollection,
     ForAll(
     yourComboBox.SelectedItems As _item,
     Patch(LookUp(someDataSource, SomeCriteria),
     {Region: _item.Region}
     )
     )
    )

     

    Sort of...the sky is the limit with what you want to achieve.  But keep in mind also, that the combobox is a Global control...you can reference it anywhere in the app and gather the information you need.

  • JR-BejeweledOne Profile Picture
    5,836 Moderator on at

     

    I see it now!   Sorry missed it.

     

    Using this how would I reference the specific combobox item

     

    Collect(TempHolidays,

        ForAll(

           combobox.selecteditems,

            { Region: comboboxitem value here  }

       )

    )

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

    @JR-BejeweledOne 

    So in that formula, you appear to just be collecting the selected Regions.  As mentioned, your combobox will already have this table and it is global.  There really is no need to collect another table/collection with the same table records of the combobox...especially to then put into a heavy-weight collection.

     

    If you need to add more than the selected items to a collection, then it's what I showed in the second formula:

    Collect(yourcollection,
     ForAll(
     yourComboBox.SelectedItems As _item,
     Patch(LookUp(someDataSource, SomeCriteria),
     {Region: _item.Region}
     )
     )
    )

    Your combobox item value will be solely based on the items property and record signature of your combobox.  So it's not possible to say what the actual column name is in your combobox that you want without knowing the Items formula and what it is based on.

    In the above formula, the assumption is that you have a column in your combobox record called Region.

     

    You can see in the formula that we are referencing the item of the selected Items table as _item.  From that, we can then reference the column (again, solely dependent on the Items of the combobox) that we want...Region, Value, Result...whatever it is based on Items.

  • JR-BejeweledOne Profile Picture
    5,836 Moderator on at

    Yea, I saw it after sorry about that.  Unfortunately in this case a collection is necessary.   I might share the whole thing with you once I get it all working.    There are a whole lot of moving parts.

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

    @JR-BejeweledOne 

    So you are planning on removing or adding rows to the rows you get from the combobox?  If not, then you can skip the collection.  If you need a snapshot of it, I recommend a variable over the collection.  Seems trivial, but it does cut down on app overhead.

  • JR-BejeweledOne Profile Picture
    5,836 Moderator on at

    Here are the basics and the balance is between app overhead and usability.    This app collects the company holidays for the upcoming year.    For 2021 we have 761 due to country, regional and local differences and as we add and lose employees or holidays that number changes.   The person submitting the holidays might be submitting for up to 20 countries at a time.

     

    The usability part is allowing them to select multiple regions for a single holiday in a country rather than creating an individual holiday for each region.   These are saved into a collection (I know) but there is a good reason.    If holidays for a country already exist in the Holiday table for a previous year, as soon as the country is selected, they are uploaded and the submitter can edit them rather than entering new ones, but they can also add new ones to the collection.   When they are done the collection is patched to the Data Source.

     

    The app also does some behind the scenes actions that require each holiday to be in a collection as a single item for each country or country/region pair, thus the 'duplicates'.

     

    There may be some ways I can clean it up and make it better once I have it working.    I had already planned on asking you to look at some of the parts once I have it working the hard way to see how it can be optimized.

     

    Here is another question:

     

    When the holidays are saved into the main holiday collection the regions are added as a text value using concat.    For edit purposes the DefaultSelectedItems is set to this:

     

    If(

    !NewItem && EditItem, Filter(RegionsColl, Region in varRecord.Region),
    CheckboxAllRegions.Checked, RegionsColl
    )

     

     

    Which gives me this:

     

    Selected.png

     

     

    Looking at this it would appear that it's not blank or empty.   However, If I modify a property, date must be modified, and then save including my new formula statement, it works BUT doesn't recognize that the combobox has any items in it.  

     

    If(!IsEmpty(ComboBoxRegion), Collect(TempHolidays, ForAll(ComboBoxRegion.SelectedItems As _item, {Region: _item.Region , Date:Text(DatePickerHolidayDate.Value), Country: DropdownCountry.Selected.Name, HolidayName: LabelHolidayNameCombined.Text}),

    IsEmpty(ComboBoxRegion), Collect(TempHolidays, {Date:Text(DatePickerHolidayDate.Value), Country: DropdownCountry.Selected.Name, HolidayName: LabelHolidayNameCombined.Text}
    )
    )
    );

     

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

    @JR-BejeweledOne 

    Consider changing your formula to the following:

    If(
     CountRows(ComboBoxRegion.SelectedItems)>0, 
     
     Collect(TempHolidays, 
     ForAll(ComboBoxRegion.SelectedItems As _item, 
     {Region: _item.Region , 
     Date:Text(DatePickerHolidayDate.Value), 
     Country: DropdownCountry.Selected.Name, 
     HolidayName: LabelHolidayNameCombined.Text
     }
     ),
    
     Collect(TempHolidays, 
     {Date:Text(DatePickerHolidayDate.Value), 
     Country: DropdownCountry.Selected.Name, 
     HolidayName: LabelHolidayNameCombined.Text
     }
    )
    

     

    Also, on the DefaultSelectedItems property:

    If(
     Filter(RegionsColl, 
     (!NewItem && EditItem && (Region in varRecord.Region)) || CheckboxAllRegions.Checked
     ) 
    )
  • JR-BejeweledOne Profile Picture
    5,836 Moderator on at

     I haven't tried the first part yet, but I get an argument error on the DefaultSelectedItems property.

     

    Invalid Number of Arguments: Received 1 expected 2 or more.

     

    Some clarification here:   CheckboxAllRegions is a separate control outside of the combobox that when checked causes all regions in the combobox to be selected.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,070

#2
Valantis Profile Picture

Valantis 639

#3
11manish Profile Picture

11manish 608

Last 30 days Overall leaderboard