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 / Creating a Search/Filt...
Power Apps
Answered

Creating a Search/Filter outside the initial view of Gallery

(0) ShareShare
ReportReport
Posted on by 116

Hi All,

 

I have figured out how to do the things I need to do, I just can't do them on the same screen using the same Gallery!  

 

When the user first lands on the page, I want them to see the gallery filtered and sorted like this (moderated=1 is important, only approved items should show in the gallery):

 

Sort(Filter('GalleryName', moderated = "1"),date,Descending)

 

Now, I want to let them search by last name.  This works, kinda - it should should still be moderated="1", my search box lets you search everything - even moderated = 0:

 

 Search('GalleryName', SearchBox.Text,"nLName")

 

To be even more complex, I also want them to filter by a choice column in my list (search employees by their specific directorate - 4 total).  I was thinking of adding 4 buttons and each button refreshes the gallery with this code.  I'm not sure how to link the button to refresh the list, I tried putting this code into the OnSelect of the button, but it didn't do anything, of course!

 

Filter('HCSO Kudos Employees', nDirectorate.Value = "AQD",moderated="1") 

 

I'm open to ideas of how to make this more simple.

 

Thank you!!!

Categories:
  • mdevaney Profile Picture
    29,993 Moderator on at

    @aharsh 

    My first suggestion is: use a single drop-down instead of buttons to let the user select nDirectorate.  Put this code in the Items property of the drop-down to populate it with the Choices values.

     

    Choices(your_datasource_name.nDirectorate)

     

    Assuming the rest of your code already works just incorporate the dropdown as shown below.

    Search(
     Filter(
     'HCSO Kudos Employees',
     nDirectorate.Value = Dropdown_nDirectorate.Selected.Valueq,
     moderated="1"
     ),
     SearchBox.Text, "nLName"
    ) 

     

    You'll get a delegation warning due to using the SEARCH function.  If you need to search past 2,000 rows the only workaround is to use STARTSWITH instead.

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • aharsh Profile Picture
    116 on at

    Hi @mdevaney ,

     

    Thank you so much, I got it working using your recommendation.

     

    How would I clear the search?  When I used the dropdown it makes the dropdown search active and the search by last name doesn't work and I can't find how to clear the dropdown search to get back to the initial view.

     

    Thanks!

  • aharsh Profile Picture
    116 on at

    Hi @mdevaney 

     

    I also realized your solution strips out the ",date,Descending" from the initial view.  I've tried multiple ways to add that back but it doesn't play nice with "search by last name" 

  • aharsh Profile Picture
    116 on at

    I'm so sorry, I'm being so obnoxious with so many messages!! @mdevaney 

     

    I have figured out how to both get the dropdown and LastName to work at the same time. As well as have the initial view start with date descending. 

     

    I'm still stuck on how to cancel the dropdown once it's activated. 

     

    Here is my current code:

     

    Search( Sort(Filter('HCSO Kudos Employees',nDirectorate.Value = Dropdown_nDirectorate.Selected.Value, moderated = "1"),date,Descending), SearchBox_1.Text, "nLName" ) 

     

    And in my dropdown

     

    Choices('HCSO Kudos Employees'.nDirectorate)

     

    I've been trying to figure out some type of "clearall" function, maybe?

     

    THank you!

  • Verified answer
    mdevaney Profile Picture
    29,993 Moderator on at

    @aharsh 

    To this I would suggest creating a collection by putting this code in the OnVisible property of the screen

     

    ClearCollect(colDropdownOptions, ["All"]);
    Collect(colDropdownOptions, Choices('HCSO Kudos Employees'.nDirectorate));

     

    Use the collection to build the dropdown by putting it in the Items property of the dropdown

     

    colDropdownOptions

     

    This dropdown will have an "All" option at the top

    Value
    All
    Choice1
    Choice2
    Choice3

     

    Finally, build this additional condition into the Items property of your gallery.

     

    Search(
        Sort(
            Filter(
                'HCSO Kudos Employees',
                Dropdown_nDirectorate.Selected.Value = "All" Or
                nDirectorate.Value = Dropdown_nDirectorate.Selected.Value,
                moderated = "1"),
            date, Descending),
        SearchBox_1.Text, "nLName"
    )

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

     

  • aharsh Profile Picture
    116 on at

    Hi @mdevaney  - You are a genius!

     

    I've been banging my head all morning trying to figure out how to wrap it in a collection, and you make it look so easy.

     

    This works perfectly.

     

    THANK YOU!!

  • mdevaney Profile Picture
    29,993 Moderator on at

    @aharsh 

    It was a pleasure to help you: I like helping others solve their PowerApps 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 345 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 225

#3
M Bilal Khan Profile Picture

M Bilal Khan 192

Last 30 days Overall leaderboard