Blog
Search - How to filter by multiple fields and return all records when no search term is entered
Building a search screen
To give an example, let's take a gallery control that displays address details. We want to enable users to filter the gallery control by either the first line of the address, or the city.
To implement this feature, we'll add two text input controls to a screen that contains a gallery control. We'll name these controls txtSearchAddress and txtSearchCity.
To adapt the gallery control so that it filters the contents in the required manner, we set the items property of the gallery control to the following formula:
Filter('[dbo].[Property]',
(City = txtSearchCity.Text Or IsBlank(txtSearchCity.Text)),
(StartsWith(Address1,txtSearchAddress.Text) Or IsBlank(txtSearchAddress.Text))
)

Taking the 'City' condition here, we specify that a match exists when the City field of a record matches City search text, OR when the user specifies a blank City search value.
How this screen appears at runtime
We can now test this screen. When the user enters no criteria, the gallery returns all rows.
When the user enters the city 'London', the gallery returns all records that match the city of 'London'.
When the user enters the city 'london' and address '3', the gallery returns all records that match the city of 'london' and an address that starts with '3'.
Conclusion
When building search screens, a very common requirement is to enable users to filter by multiple fields and to return all records if no search criteria is entered. This post described how to carry out this task.- Categories:
- search
- screen design
- Search - Applying multiple AND/OR conditions to the Search function- Workaround
- Search - How to filter records by date ranges (eg today, this week, this month, etc)
- Search - How to highlight search terms in search results
- SharePoint - Choice function now includes search capability
- Search - Filter records using A-Z control on a Canvas app