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 / ForAll Items in ComboBox
Power Apps
Answered

ForAll Items in ComboBox

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

I have a multi-select combobox that provides data for a couple different functions.   In one function I need to add each selected item in the combobox to it's own row in a collection, along with other data.  The multi-select function is necessary for app usability.

 

HolidayCapture.png

 

Holidaytool.png

 

I do have a formula that will create the individual rows, but it creates multiple instances of each row.

 

The Comboxbox items are a collection of regions.   The collection is cleared and repopulated each time a different country is selected as shown below.  Multiple Holidays are added to the Holiday collection for the same country, but the regions for each specific holiday will vary.   For the examples below I have just used all the regions.

 

 

ClearCollect(RegionsColl, 
 
 ShowColumns(
 
 Filter(Regions, Country.Name in DropdownCountry.Selected.Name And "Yes" in Active),
 "crc39_name"
 ));

 

 

 

BrazilBrazil        CanadaCanada

 

This is the formula that adds the Combobox items to the collection

 

 

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

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

 

 

When this runs it adds each row twice.  Every time it runs after the first time, the new items are added AND each previous entry is added again (twice) even if the Regions collection no longer contains the same regions.

 

1st Run:  2 sets of entries (2 rows for each region and 2 blank rows)

2nd Run: 2 sets for the newly selected regions, 4 sets for the originally selected regions

3rd Run: 2 sets for the newly selected regions, 4 sets for the regions selected in the 2 run and 6 sets for the regions selected in the 1st run.

 

Here are screenshots.   For the 2nd image I have removed the blank rows so you can see what is happening more easily

 

EventIndexInitial.png

 

EventIndex.png

 

@RandyHayes @Shanescows @Reza 

I have the same question (0)
  • Drew Poggemann Profile Picture
    9,287 Most Valuable Professional on at

    Hi @JR-BejeweledOne,

     

    Do you have code somewhere in your logic that is clearing the ComboBoxRegion.SelectedItems when the country changes?  This might be a stupid question but I don't see where this is cleared so as you add more items it is going to include the items you had selected in the past as well so continue to duplicate every time.  Just a thought...

     

    Thanks,


    Drew

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

    The ComboBox items is a collection.   The issue occurs regardless if the country is changed.  

     

    OnChange formula for the country dropdown:

     

    ClearCollect(RegionsColl,

    ShowColumns(

    Filter(Regions, Country.Name in DropdownCountry.Selected.Name And "Yes" in Active),
    "crc39_name"
    ));

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

    So, the formula didn't give me any errors or indicators (red squigglies) that something wasn't right and worked but not correctly.   The solution?  Add an additional close paren at the end of the first If action.

     

    If(
     CountRows(ComboBoxRegion.SelectedItems) >0 && CountIf(EventIndex, Region in ComboBoxRegion.SelectedItems.crc39_name && HolidayName in LabelHolidayNameCombined) = 0,
     
     Collect(EventIndex,
     ForAll(ComboBoxRegion.SelectedItems As _item,
     {Region: _item.crc39_name, 
     Date:Text(DatePickerHolidayDate.Value),
     Country: DropdownCountry.Selected.Name,
     HolidayName: LabelHolidayNameCombined.Text
     }
     )
     ),
    
     Collect(EventIndex,
     {Date:Text(DatePickerHolidayDate.Value),
     Country: DropdownCountry.Selected.Name,
     HolidayName: LabelHolidayNameCombined.Text
     }
     )
     )
    );

     

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…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard