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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Filtering a collection
Power Apps
Answered

Filtering a collection

(0) ShareShare
ReportReport
Posted on by 47

Hi

 

I have a GalleryDetails with text input controls for creating new records.

  1. When I enter a few records in this gallery, I click the save button and this data gets saved into a collection
  2. Then I click another save button to write it to the Common Data Service with the patch function.

This works great for creating new records but now I want to edit those records in that same GalleryDetails based on a record that I select in another Gallery thats named GalleryMaster

 

So I've created an edit button with this code to:

  1. get the records back from the Common Data Service Entity "CDSDetails"
  2. put those records in the CollectionDetails
  3. And show them in my GalleryDetails so I can edit them

This is the edit button OnSelect to create the above magic:

Collect(
 CollectionDetails;
 Filter(
 CDSDetails;
 MasterID = GalleryMaster.Selected.ID
 )
)

But unfortunately this formula doesn't work. I admit I don't yet fully understand collections. Maybe the formula is correct but "MasterID" isn't. This field is a lookupfield as it represents a relationship between CDSMaster and CDSDetails in the common data service and for some reason it's dotted in blue as a warning for delegation, but even then it just doesn't work as I'm below 500 records at this moment and the button doesn't work at all...

If I change MasterID to ID the formula works but the information that is shown in the GalleryDetails is not correct at all as it shows a blank gallery...

 

Any help is much appreciated!

 

Categories:
I have the same question (0)
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Hi @svenvu 

    It appears to me that your app is unnecessarily complicated because you are trying to use galleries for data input.  In general, galleries are used to display data (think of it as a report) and forms are used for creating new records and editing existing records.  In relational databases, you will use galleries to select a subset of records to edit, for example, customers and orders.  In that case you would use 2 galleries and 2 edit forms, one for the details of the customer and one for the details of the order.  For an example, please check my post in the Community Blog Relational-Database-Design-fundamentals-Implementing-a-One-to-many relationship in PowerApps

  • svenvu Profile Picture
    47 on at

    Hi @Drrickryp 

     

    Thank you for the link. I found it very useful, especially the "ID" parts, as I still need to learn a lot!

    I understand the basic concept of galleries vs forms but unfortunately forms only allow editting one item and that isn't very userfriendly for heavy data input when users need to enter many items. In my case: create a masterItem and immediately create 4 subitems with 6 columns. I don't see any other userfriendly way of creating such a solution.

     

    I can use the form for creating the masteritem but then I must use a gallery with 4 rows of 6 inputcontrols as a kind of editable table. The benefit of a gallery is that I only need to create 6 inputcontrols that are automatically created in the 3 rows below = total of 4 galleryitems. This gallery is set by a collection of 4 rows so the gallery shows 4 items that the user can fill in. The filled in inputboxes needs to be saved back to the collection and then saved to the real CDS-datasource.

     

    I found some info on ForAll with a Patch-function and try that later instead of Collect.

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Hi  @svenvu 

    If you want to see some extremely clever uses of galleries for data input, check out @Shanescows  videos nfopath+form+powerapps.  I believe that you will get some great ideas from this as to how to present your app to your users.  Infopath was one of the precursors to Powerapps that was deprecated by Microsoft but it still had dedicated users who needed to transition.  What you want to do is not an out of the box solution in PowerApps but others have blazed that trail for you.  See what you think.  Shane has many videos that are extremely practical and were my guide to learning PowerApps. 

  • Verified answer
    svenvu Profile Picture
    47 on at

    Thank you! I watched some videos of Shane and this was very helpful! Funny guy 🙂 For the above problem I eventually used:

     

    Clear(CollectionDetails);;
    
    ForAll(
     GalleryMaster.Selected.CDSDetails;
     Patch(
     CollectionDetails;
     Defaults(CollectionDetails);
     ...

    GalleryMaster.Selected.CDSDetails passes the ID to the CDSDetails Entity. Changing this part with a Filter-function didn't work... very strange...I probably still don't understand how to pass an ID that is selected in a gallery to the many side of a relationship in CDS with a filter-function without delegation issues.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard