cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kriggo15
Responsive Resident
Responsive Resident

Add all items from gallery to collection that are not already in the collection

I am trying to allow the end user to choose items from a gallery either individually or by allowing them to add all items to a collection at once if it doesn't already exist. I can do this by the 1s no problem, but am having issues figuring out the logic for my "Add All" button.

In the example below, clicking "Add All" should add the 5 remaining items in my gallery on the left not already in my collection on the right. The logic below will add the same items to the collection but I can't seem to figure out the inverse of it. Is there some version of "not in" I could use?

ForAll(
    Gallery1_2.AllItems,
    If(ThisRecord.Value in Gallery1_3.AllItems.Value, Collect(colTest, ThisRecord)));


Fruit.png

1 ACCEPTED SOLUTION

Accepted Solutions
TheRobRush
Super User
Super User

Ok so here it goes, 

In the image below I have two galleries, side by side. 

One is set to the source of TMROSTER, and the other TeamRoundUp (A collection)

StartingSpot.PNG

On the chevron icon to right of my itesm I have the following in its icon setting

If(CountRows(Filter(TeamRoundup,ID=ThisItem.ID))>0,Icon.Cancel,Icon.ChevronRight)

Which gives me a visual indicator if it is in the collection (X if it is, > if it is not yet) 

Onselect has a code of

If(CountRows(Filter(TeamRoundup,ID=ThisItem.ID))>0,RemoveIf(TeamRoundup,ID=ThisItem.ID),Collect(TeamRoundup,ThisItem))

which allows me to use the icon to both add and remove the item from the roundup

Underneath all the info for the item you will see a number 1/0 etc this is just a text control for when I was testing my collect to ensure no item got missed or DOUBLE collected by counting the occurences of this item in the roundup, its text code is

CountRows(Filter(TeamRoundup,ID=ThisItem.ID))

My other gallery shows all the items that have been collected

Couple In.PNG

Now the button up above, Add remaining, is what you are looking for, and here is its onselect

Collect(TeamRoundup,

        ForAll(
                Gallery2.AllItems,
                If(Not(ThisRecord.ID in TeamRoundup.ID), ThisRecord)))

Clicking it pulls a list of all the items not in the collection, then collects them.

You can click it 100 times and it will not readd already existing items. Only those not present in the colleciton

alladded.PNG

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

View solution in original post

5 REPLIES 5
TheRobRush
Super User
Super User

You should.place the forall inside the collect, as opposed to collect in the forall, it will work better

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!
kriggo15
Responsive Resident
Responsive Resident

Thanks. Though I'm still confused on how to get those not already in the collection.

TheRobRush
Super User
Super User

give me a second and I will type an example

 

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!
TheRobRush
Super User
Super User

Ok so here it goes, 

In the image below I have two galleries, side by side. 

One is set to the source of TMROSTER, and the other TeamRoundUp (A collection)

StartingSpot.PNG

On the chevron icon to right of my itesm I have the following in its icon setting

If(CountRows(Filter(TeamRoundup,ID=ThisItem.ID))>0,Icon.Cancel,Icon.ChevronRight)

Which gives me a visual indicator if it is in the collection (X if it is, > if it is not yet) 

Onselect has a code of

If(CountRows(Filter(TeamRoundup,ID=ThisItem.ID))>0,RemoveIf(TeamRoundup,ID=ThisItem.ID),Collect(TeamRoundup,ThisItem))

which allows me to use the icon to both add and remove the item from the roundup

Underneath all the info for the item you will see a number 1/0 etc this is just a text control for when I was testing my collect to ensure no item got missed or DOUBLE collected by counting the occurences of this item in the roundup, its text code is

CountRows(Filter(TeamRoundup,ID=ThisItem.ID))

My other gallery shows all the items that have been collected

Couple In.PNG

Now the button up above, Add remaining, is what you are looking for, and here is its onselect

Collect(TeamRoundup,

        ForAll(
                Gallery2.AllItems,
                If(Not(ThisRecord.ID in TeamRoundup.ID), ThisRecord)))

Clicking it pulls a list of all the items not in the collection, then collects them.

You can click it 100 times and it will not readd already existing items. Only those not present in the colleciton

alladded.PNG

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!
kriggo15
Responsive Resident
Responsive Resident

Thank you, @TheRobRush. Your add remaining code worked perfectly. Thanks again.

Helpful resources

Announcements
Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Government Carousel

New forum: GCC, GCCH, DoD - Federal App Makers (FAM)

In response to the unique and evolving requirements of the United States public sector, Microsoft has created Power Apps US Government.

Users online (2,309)