cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JR-BejeweledOne
Super User
Super User

ForAll Items in ComboBox

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 



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
1 ACCEPTED SOLUTION

Accepted Solutions
JR-BejeweledOne
Super User
Super User

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
     }
    )
  )
);

 



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

View solution in original post

3 REPLIES 3
dpoggemann
Super User
Super User

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

Hope this helps. Please accept if answers your question or Like if helps in any way.
Thanks,
Drew
JR-BejeweledOne
Super User
Super User

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



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
JR-BejeweledOne
Super User
Super User

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
     }
    )
  )
);

 



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Users online (1,259)