Skip to main content

Notifications

Power Apps - Building Power Apps
Suggested answer

ClearCollect & Filter

(1) ShareShare
ReportReport
Posted on by 4
I'm new to PowerApps. I had someone in my company who was very capable recently leave, so my source of review/corrections has also left. ChatGPT is not helping me solve this issue either as I've exhausted the troubleshooting and everything checks, so looking to you for help as I'm not getting the expected results.
 
I am building an app that collects and displays data. Screen1 has a dropdown list of projects (FilterDrop_ProjectName), which then populates a gallery (GalleryDesignPackageCategories) which is a checkbox list of categories. A user would then pick the categories they would like to see, and it populates the package details in another gallery (Gallery4). 
 
FilterDrop_ProjectName OnChange property I have:
UpdateContext({filteredProjectName: Trim(FilterDrop_ProjectName.Selected.NewProjectName)})
 
GalleryDesignPackageCategories (the gallery), Check_ProjectCategory (the repeating check box populated by ProjectName) OnCheck property I have: 
Collect(SelectedPackageCategories, ThisItem.Value)
 
Table '[DPC] Design Package Coordinations' has the following columns:
ProjectName - Text
PackageCategory - Text
 
Screen1 OnVisible property I have:
ClearCollect(
    colGallery4Data,
    Filter(
        '[DPC] Design Package Coordinations',
        ProjectName = filteredProjectName && PackageCategory in SelectedPackageCategories
    )
);
 
When I add a text label to count the rows of colGallery4Data, it ends up as 0, but it should return 8. I've reduced the ClearCollect to try and show just ProjectName or PackageCategory, but no matter what it comes back 0, and won't populate my Gallery4 content. What's wrong with my ClearCollect or Filter functions? 
Categories:
  • WarrenBelz Profile Picture
    WarrenBelz 145,434 on at
    ClearCollect & Filter
    A quick follow-up to see if you received the answer you were looking for or if you need further assistance.

    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
  • WarrenBelz Profile Picture
    WarrenBelz 145,434 on at
    ClearCollect & Filter
    OK - I see now your gallery is a one-field item with (I assume) the checkboxes displaying the Value field, so for the last Collection
    With(
       {
          _Data:
          Filter(
             '[DPC] Design Package Coordinations',
             ProjectName = filteredProjectName
          )
       },
       ClearCollect(
          colGallery4Data,
          Filter(
             _Data,
             PackageCategory in SelectedPackageCategories.Value
          )
       )
    );
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
  • MR-14011956-0 Profile Picture
    MR-14011956-0 4 on at
    ClearCollect & Filter
    Thank you for the response and help! Ok, I had that code on OnCheck of Check_ProjectCategory, but you're saying I should instead put it on OnSelect of GalleryDesignPackageCategories? I have tried that, but there is still no change. I currently put it back to OnCheck of Check_ProjectCategory. Here's the other codes you asked about:
     
    Items for GalleryDesignPackageCategories:
    Distinct(
        Filter(
            '[DPC] Design Package Coordinations',
            ProjectName = FilterDrop_ProjectName1.Selected.NewProjectName
        ),
        PackageCategory
    )
    Default for Check_ProjectCategory:
    false
    Default for GalleryDesignPackageCategories:
    false
     
     
  • WarrenBelz Profile Picture
    WarrenBelz 145,434 on at
    ClearCollect & Filter
    The key here is the change I made to the OnSelect of the checkbox in the Gallery, assuming you had records in there to select
    Collect(SelectedPackageCategories, ThisItem)
    What is the Items of GalleryDesignPackageCategories and the Default of Check_ProjectCategory ?
  • MR-14011956-0 Profile Picture
    MR-14011956-0 4 on at
    ClearCollect & Filter
    Thank you @WarrenBelz. 
     
    I did make the suggestions that you have made. Because PackageCategory wasn't recognized after SelectedPackageCategories, I updated to this:
    With(
       {
          _Data:
          Filter(
             '[DPC] Design Package Coordinations',
             ProjectName = filteredProjectName
          )
       },
       ClearCollect(
          colGallery4Data,
          Filter(
             _Data,
             PackageCategory in SelectedPackageCategories
          )
       )
    );
    Could that small update have an impact on my results? 
     
    Besides that, I've restarted the app and I continue to get nothing back:
    colGallery4Data rows: 0
  • Suggested answer
    WarrenBelz Profile Picture
    WarrenBelz 145,434 on at
    ClearCollect & Filter
    Firstly (small improvement on this one) - FilterDrop_ProjectName OnChange
    UpdateContext({filteredProjectName: Self.Selected.NewProjectName})
    GalleryDesignPackageCategories  -  Check_ProjectCategory OnCheck
    Collect(SelectedPackageCategories, ThisItem)
    Screen1 OnVisible (I assume you are changing to this after you set the items above)
    ClearCollect(
       colGallery4Data,
       Filter(
          '[DPC] Design Package Coordinations',
          ProjectName = filteredProjectName && PackageCategory in SelectedPackageCategories.PackageCategory
       )
    );
    If you are concerned about Delegation on the last one
    With(
       {
          _Data:
          Filter(
             '[DPC] Design Package Coordinations',
             ProjectName = filteredProjectName
          )
       },
       ClearCollect(
          colGallery4Data,
          Filter(
             _Data,
             PackageCategory in SelectedPackageCategories.PackageCategory
          )
       )
    )

    ​​​​​​​Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,434

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,722

Leaderboard