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 Gallery on T...
Power Apps
Unanswered

Filtering Gallery on Two Tables

(0) ShareShare
ReportReport
Posted on by 163

Hey all, I'm having trouble coming up with a solution for a gallery filtering problem I have.

 

I have a search box for my gallery and my gallery items property is set to: If(IsBlank(SearchInput.Text),Filter(Assignments,UserID='User List'.Selected.UserID),Filter(Offices, SearchInput.Text in OfficeName))

 

The gallery item text labels are set to LookUp(Offices,ID=ThisItem.OfficeID,OfficeName)

 

So the gallery is showing office assignments based on a selected user in another gallery and displaying the name of the office rather than it's ID. The problem I am having is in the first formula:

 

If(IsBlank(SearchInput.Text),Filter(Assignments,UserID='User List'.Selected.UserID),Filter(Offices, SearchInput.Text in OfficeName))

 

If the search box is blank, then show office assignments for the selected user, otherwise filter by whatever is in the search box. I need a way to include the Filter(Assignments,UserID='User List'.Selected.UserID) in the second half of this formula. Currently, when you do a search it will return all office names regardless of if they are assigned to the user. So I need to be able to filter the list based on the search term, but only show results if they are assigned to the userID. Hope that makes sense.

 

Any help is appreciated!

Categories:
I have the same question (0)
  • JR-BejeweledOne Profile Picture
    5,836 Moderator on at

    Try something like this.

     

    If(

    IsBlank(SearchInput.Text),Filter(Assignments,UserID='User List'.Selected.UserID),
    Filter(Filter(Offices, SearchInput.Text in OfficeName), Assignments,UserID='User List'.Selected.UserID)

    )

  • stephenkln Profile Picture
    163 on at

    Hey @JR-BejeweledOne thanks for the response. That did not work unfortunately.

     

    I'm getting an error on the source portion of the second filter function..
    Filter(Filter(Offices, SearchInput.Text in OfficeName),Assignments,UserID='User List'.Selected.UserID))

     

    "The function 'Filter' has some invalid arguments. Expected boolean. We expect a boolean (true/false) at this point in the formula."

     

    I tried changing the formula to Filter(Filter(Offices, SearchInput.Text in OfficeName),Assignments.UserID='User List'.Selected.UserID)) but then I get an "invalid argument type" error on the "=".

  • JR-BejeweledOne Profile Picture
    5,836 Moderator on at

    What is your data source for the gallery?

  • stephenkln Profile Picture
    163 on at

    @JR-BejeweledOne Several excel spreadsheets in OneDrive.

     

    Offices is basically:

     

    OfficeIDOfficeName
    1A
    2B

     

    Assignments is:

     

    AssignmentIDUserIDOfficeID
    111
    212
    321
  • JR-BejeweledOne Profile Picture
    5,836 Moderator on at

    I think you will need to do something like this.

     

    First set a variable to the user id when it's selected from the User List.   I have used varUser for that here.

     

    then something like this.

     

    If(

    !IsBlank(SearchInput.Text), Filter(Offices, OfficeID in Filter(Assignments, varUser in UserID).OfficeName And SearchInput.Text in OfficeName),

    Filter(Assignments,UserID='User List'.Selected.UserID)
    )

     

    I had to do something similar yesterday

     

    Filtering items in a gallery where the category matched the assigned category for the current user in another list.  Mine had some multi-selects, but it looks like this:

     

    Validateagainstotherlist.jpg

     

     

  • stephenkln Profile Picture
    163 on at

    @JR-BejeweledOne I think this got me closer, but still having trouble...

     

    If(IsBlank(SearchInput.Text),Filter(Assignments,UserID='User List'.Selected.UserID),Filter(Offices, OfficeID in Filter(Assignments, varUser in Assignments.UserID).OfficeName And SearchInput.Text in OfficeName)
    )

     

    OfficeName is not valid at that point in the formula, it's only letting me select from the Assignments table for the value at that point.

  • stephenkln Profile Picture
    163 on at

    Bump. Anyone have any other suggestions on how to get this gallery to do what I need it to do? Currently, my items formula is:

     

    If(IsBlank(SearchInput.Text),Filter(Assignments,UserID='User List'.Selected.UserID),Filter(Assignments,UserID='User List'.Selected.UserID && SearchInput.Text in Filter(Offices,OfficeID in Assignments.OfficeID).OfficeName))

     

    I've also tried 

     

    If(IsBlank(SearchInput.Text),Filter(Assignments,UserID='User List'.Selected.UserID),Filter(Assignments,UserID='User List'.Selected.UserID && SearchInput.Text in LookUp(Offices,OfficeID in Assignments.OfficeID,OfficeName)))

     

    Neither produces the behavior I need. I need the gallery to display all associated items for the selected user if there is nothing in the search box. Otherwise I need the gallery to filter to any items assigned to the selected user that contain the search text.

     

     

  • WarrenBelz Profile Picture
    153,049 Most Valuable Professional on at

    Hi @stephenkln ,

    This is only some syntax guidance to assist - you may need something like this

    With(
     {
     wOfficeID:
     Filter(
     Offices,
     OfficeID in Assignments.OfficeID
     ).OfficeName
     },
     Filter(
     Assignments,
     UserID='User List'.Selected.UserID &&
     If(
     IsBlank(SearchInput.Text),
     Filter(
     Assignments,
     SearchInput.Text in wOfficeID
     )
     )
     )
    )

     

    Please click Accept as solution 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 Thumbs Up.

  • Verified answer
    stephenkln Profile Picture
    163 on at

    I finally figured it out. I used Filter in combination with ShowColumns and AddColumns to basically create a new virtual table in PowerApps that had all three of my filter attributes (UserID, OfficeID, OfficeName) in the same place.

     

    If(IsBlank(SearchInput.Text),Filter(Assignments, UserID='User List'.Selected.UserID), Filter(ShowColumns(AddColumns(Assignments,"OfficeNameLookup",LookUp(Offices,OfficeID=Assignments[@OfficeID],OfficeName)),"AssignmentID","UserID","OfficeID","OfficeName"),UserID='User List'.Selected.UserID && SearchInput.Text in OfficeName))

     

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 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