web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to collect all vis...
Power Apps
Answered

How to collect all visible items in a filtered Gallery into an existing collection? ClearCollect(Collection, Gallery.AllItems) results in conflict in other areas dealing with the same Collection.

(1) ShareShare
ReportReport
Posted on by 189

I have a Gallery with items from a CDS entity. It is filtered so it never shows all records. I have a Collection meant for those items.

 

Each template in the Gallery has a Checkbox with the following formulas:

 

OnCheck: Collect(Collection, ThisItem)
OnUnCheck: Remove(Collection, ThisItem)
Default: ThisItem in Collection

 

 

Outside of my Gallery I have a Deselect button with the following formula:

 

OnSelect: Clear(Collection)

 

 

Clicking it will also clear any checkboxes due to their default value.

 

Everything above works perfectly. Below is where it fails.

 

Also outside of my Gallery, I want a SelectAll button to collect all visible items in my Gallery into the same Collection. Once it has done that, all my checkboxes will show up checked appropriately due to their Default value being tied to their participation in the Collection.

 

I have read many other posts here. I cannot achieve this by:

  • setting SelectAll.OnSelect = Set(varAllSelected, true)
  • setting Checkbox.Default = If(ThisItem In Collection, true, varAllSelected)

because it is not enough to have the ✓ show up, it is not the value of the checkbox that puts the item in the collection but the action of checking it. So doing this doesn't add it to Collection.

 

I tried the following formula:

 

OnSelect: ClearCollect(Collection, Gallery.AllItems)

 

 

But I get an error on my Checkbox.OnCheck and Checkbox.OnUnCheck formulas, saying the item I'm trying to add to a collection is not of a compatible type. 

 

Why is AllItems not the same type as ThisItem?

 

I've also tried using ForAll but I don't quite know how to use it.

 

My objectives:

1) How to add all items from a Gallery to a collection? (I don't care about columns, I want all columns added but I don't know and don't care what they are and I'd prefer not to have to list them all out.)

2) Will the above solution guarantee that I'm only collecting the visible items in the Gallery and not the whole set of records fron Entity Name? My Gallery is filtered: 

 

Gallery.Items = Filter('Entity Name','Created by'.'Full Name' = User();'Full Name')

 

 

This is really doing my head in. Please and thank you to anyone who can help and much appreciated!

Categories:
I have the same question (0)
  • GarethPrisk Profile Picture
    2,828 on at

    You mentioned you have a Gallery that is using a CDS entity as its source. I would propose that you collect values from CDS, using a replica of the Gallery's filter.

     

    How are you controlling the rows in that Gallery?

    • Filter functions - easily replicated
    • Filter (CDS View) - easily replicated
    • Search - need to add a function to replicate how Search retrieves data from column(s)

     

    Either way, you should have a good understanding of what is dictating the rows that are being shown in the gallery. Now you can apply that same filtering logic, for a Collect statement.

    • Simply: Collect ( Collection , {Identical Filtering as Gallery} )
    • Example: Collect( colCheckedItems, Filter ( cdsEntity , cdsColumn1 = filterValue, cdsColumn2 in searchValue ) )
    • This will be subject to delegation, and will get records up to X of your app's data row limit value

     

    NOTE:

    • If you are showing a directly connected CDS entity, it will show you records which are able to be seen on the screen at the time
    • It will retrieve more records as you scroll the list, but not initially
    • If you expect that the total records (after all scrolling) will exceed your app's data row limit, then you may need to consider an alternate approach
  • Verified answer
    Lexicon_ Profile Picture
    189 on at

    Hi GarethPrisk, 

     

    Thank you for your response!

    I actually fixed my issue earlier but my post got autoflagged as spam and I couldn't add my solution and close it.

    I went with what you said as well, by changing my ClearCollect to 

     

    ClearCollect(Collection, Filter('Entity Name','Created by'.'Full Name' = User();'Full Name'))​

    I also had to update my Checkbox.Default value to

     

    ThisItem.UniqueName in Collection.UniqueName

     

    Everything works now.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 392 Most Valuable Professional

#2
11manish Profile Picture

11manish 181 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 112 Super User 2026 Season 2

Last 30 days Overall leaderboard