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 Apps - Building Power Apps
Under review by Community Managers

Under review

Thank you for your post! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Filter a Gallery with a Property of a Related Table

Posted on by
I am building a canvas app to track projects using Dataverse for the back end. I have two tables named Site (think of this as a physical location) and Phase. Phase has a lookup column to Site as one site can have multiple phases, but a phase can only belong to one site. On the Power App, there are two text input fields and two galleries on a single screen. In the first version of the app, the two text input fields were for Site Number (a text column on the Site table) and Customer Number (also a text column on that table). The first gallery was for sites and the second was for phases. The text in the two text input fields was used to filter sites, and then the selected site from the 1st gallery would filter the phases gallery. The code for the sites gallery looked like this:
Sort(
    Filter(
        Sites,
        And(
            Or(
                IsBlank(txt_SiteNum.Value),
                StartsWith(
                    SiteNum,
                    txt_SiteNum.Value
                )
            ),
            Or(
                IsBlank(txt_CustNum.Value),
                StartsWith(
                    CustNum,
                    txt_CustNum.Value
                )
            )
        )
    ),
    'Created On',
    SortOrder.Descending
)
 
However, I've recently learned that the customer number is actually a property of the phase and not the site. I've added that column to my Dataverse table for phases, but now I'm having a hard time using the customer number to filter the sites gallery. I basically need to filter the Sites table for any records which have phases where the customer number is equal to (or StartsWith() if possible) the number entered in txt_CustNum. This is the closest I've been able to get, but I don't know if there is a better way I should be doing this. The code below doesn't work:
With(
    {
        scpPhasesForCustomer: Filter(
            Phases,
            Or(
                IsBlank(txt_CustNum.Value),
                StartsWith(
                    CustNum,
                    txt_CustNum.Value
                )
            )
        ).SiteID
    },
    Sort(
        Filter(
            Sites,
            And(
                Or(
                    IsBlank(txt_SiteNum.Value),
                    StartsWith(
                        Number,
                        txt_SiteNum.Value
                    )
                ),
                ThisRecord in scpPhasesForCustomer
            )
        ),
        'Created On',
        SortOrder.Descending
    )
)
 

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 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard

Featured topics