A gallery control is used to show multiple records from a data source, and each record can contain multiple types of data. To filter the records in gallery we can use various in-built function such as Filter with StartsWith or Search function.
Let’s see how to filter and search an items in gallery.

Filtering and Searching an items in Gallery
Let’s create a search box experience for the end user. We will add a search box that allows users to search for records by Category and Segment in the gallery.
First, let’s add a Text input control and style it to resemble a search box

Now, name it txt_search and set its Default text value to blank by removing any existing default text.
Next, provide a Hint text “Search by Category and Segment”.

Now, go to an Item property of gallery control and write below formula.
Filter( Orders, (StartsWith( Category, txt_search.Text ) || StartsWith( Segment, txt_search.Text )) )

StartsWith( Category, txt_search.Text ) || StartsWith( Segment, txt_search.Text )
The Filter function then returns a set of records in a table format that meet the StartsWith condition.
Now, run the app. You will see that it searches for items in the gallery with the Category value of Technology, as well as the Segment value of Home Office.

Now, we will filter the gallery records by country using a dropdown control.
Add a drop down control, and named it drp_country.

Next, bind the dropdown to the Country data. To do this, set the Items property of the drp_country control to the formula below.
Distinct( Orders, Country )

Next, add a Text label control and set its Text property to “Country.”

Now, navigate to the Items property of the gallery control and modify the existing formula. We will add an additional condition to filter the records based on the country selected in the dropdown.
Filter( Orders, (StartsWith( Category, txt_search.Text ) || StartsWith( Segment, txt_search.Text )) && (Country = ddl_Country.Selected.Value) )

Let’s run the app, and you will see that it filters the gallery items for the selected Country, Australia, and the Segment, Consumer.

If you want to allow an empty selection in the Country dropdown, go to the Advance properties of the dropdown control and set the AllowEmptySelection property to true, as shown below.

Once you allow empty selection for the dropdown, it will display an empty option by default if no value is selected in the Country dropdown.
You will notice that as soon as you allow an empty selection for the dropdown, the gallery does not display any records.
This happens because it checks for records where the country value is empty or blank. To address this situation, we need to modify the code in the Items property of the gallery control.
Filter( Orders, (StartsWith( Category, txt_search.Text ) || StartsWith( Segment, txt_search.Text )) && (Country = ddl_Country.Selected.Value || ddl_Country.Selected.Value =Blank()) )
Now, you can see that no item is selected in the Country dropdown. In this case, all records in the gallery control are filtered to show only those with the Segment set to Consumer.

Now, when you select a country, all records in the gallery control are filtered based on the selected Country and the string provided in the text input control for Segment or Category.
Let’s select Country Germany and this time, instead of Segment, we will search for items in the Category of Technology.

Using Filter with Search function
Instead of using the StartsWith function, you can also use the Search function, which searches for the string provided in the text input control within the gallery’s items for both Category and Segment, allowing for partial matches within the data of these items.
Let’s modify the previous formula as shown below.
Search( Filter( Orders, (Country = ddl_Country.Selected.Value || ddl_Country.Selected.Value = Blank()) ), txt_search.Text, "Category", "Segment" )


Also Read..
Highlight selected item in gallery
Sort Items in gallery Power Apps
Change Item color in gallery based on value
![]()
