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 / How to add a search fi...
Power Apps
Unanswered

How to add a search field to a Gallery and allow user to select from 2 search fields

(1) ShareShare
ReportReport
Posted on by 753

I have an app with a Gallery that shows the contends of a SharePoint List. I have buttons that allows the user to see Archived data and Active data. That has been working fine, but I am trying to add search functionality. I added a dopdown field to select the SharePoint List field to search in and a field to enter the search value. Here is a screenshot of what I have, including the code:

Greg27_1-1699561933682.png

 

 

Pressing the Search button will set varGalleryFilter = 5 and my Gallery Items function includes the following code:

Filter(
Sort(
VehicleRegistration,
Created,
SortOrder.Descending
),
VehicleOnCampus = "Yes",
(Status = "New" && (varGalleryFilter = 1 || varGalleryFilter = 3)) ||
((Status="Rejected" || Status="Completed") && (varGalleryFilter = 2) ||
((varGalleryFilter = 5) & (dd_SearchField.Selected.Value="LicensePlateNumber" && LicensePlateNumber=lblSearchValue.Text) || (dd_SearchField.Selected.Value="RegistrantID" && RegistrantID=lblSearchValue.Text))
)

 

My SharePont List fields are LicensePlateNumber and RegistrantID. My dropdown field is dd_SearchField and the Label for entering the search value is lblSearchValue. It doesn't seem to understand lblSearchValue.Text and I am not sure if this is the best way to do this. Just looking for some help.

Categories:
I have the same question (0)
  • Verified answer
    M_Ali_SZ365 Profile Picture
    1,110 on at

    Hi @Greg27 ,

    Try This Formula 

    To add a functional search feature in your PowerApps Gallery based on two SharePoint List fields, ensure you're using a Text Input control for the search term instead of a label. Then update your Gallery Items formula to:

    Filter(
     Sort(
     VehicleRegistration,
     Created,
     SortOrder.Descending
     ),
     VehicleOnCampus = "Yes",
     (Status = "New" && (varGalleryFilter = 1 || varGalleryFilter = 3)) ||
     ((Status = "Rejected" || Status = "Completed") && (varGalleryFilter = 2)) ||
     ((varGalleryFilter = 5) && (
     (dd_SearchField.Selected.Value = "LicensePlateNumber" && LicensePlateNumber = TextInputSearchValue.Text) ||
     (dd_SearchField.Selected.Value = "RegistrantID" && RegistrantID = TextInputSearchValue.Text)
     ))
    )

    Replace lblSearchValue.Text with TextInputSearchValue.Text, and make sure dd_SearchField Items property has choices that match your searchable SharePoint fields. This should allow you to search for "LicensePlateNumber" or "RegistrantID" based on the dropdown selection and the input provided.

    Please accept this solution if it resolves the issue. ✅
    Best regards,
    Muhammad Ali

  • Hassan_SZ_365 Profile Picture
    542 on at

    Hi @Greg27 ,

    To add search functionality to a gallery based on user-selected fields in Power Apps, you need to use the value entered in the search field to filter the gallery items. The error in your formula seems to be due to the incorrect use of the logical AND operator & instead of &&.

    Here's the corrected formula:

     

    Filter(
     Sort(
     VehicleRegistration,
     Created,
     SortOrder.Descending
     ),
     VehicleOnCampus = "Yes",
     (Status = "New" && (varGalleryFilter = 1 || varGalleryFilter = 3)) ||
     ((Status = "Rejected" || Status = "Completed") && varGalleryFilter = 2) ||
     (varGalleryFilter = 5 && (
     (dd_SearchField.Selected.Value = "LicensePlateNumber" && LicensePlateNumber = lblSearchValue.Text) ||
     (dd_SearchField.Selected.Value = "RegistrantID" && RegistrantID = lblSearchValue.Text)
     ))
    )

     

    Make sure dd_SearchField.Selected.Value matches exactly the internal name of the SharePoint List columns, and lblSearchValue.Text contains the value you want to search for. This formula also assumes that varGalleryFilter is set correctly when the search button is clicked.

     

    Best Regards,
    Hassan Raza

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