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.


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"
));
Brazil
Canada
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


@RandyHayes @Shanescows @Reza