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!

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
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (4,646)