Search function in Power Apps

The Search function returns only those records from a table that contains a string (may be a partial match) in one of their columns specified in the Search function itself. The Search function is case-insensitive.

Power Apps Syntax Search(Table, SearchString, Column1 [, Column2, ... ] )

Note: • The column name should be in single quotes if the column name has space in its name otherwise, we can omit the single quotes (for example, Name and ‘Total Marks’).
• The column names must be static and cannot be calculated with a formula.
• If SearchString is found within the data of any of these columns as a partial match, the full record will be returned.

Example: Demonstrate the use of Search function in Canvas Power Apps.

1. Collection as the Data Source

Follow the following steps to use Search function with Collection as a data source.
Step 1: Select the + Insert tab in the Canvas app and add a Button control, and set its OnSelect property to the following powerapps formula.

Power Apps Formula

ClearCollect(MyNewCollection,
{Name: "Ashish" , Country: "India", Profession: "Engineer"},
{Name: "Deepak", Country: "America", Profession: "Engineer"},
{Name: "Anjali", Country: "India", Profession: "Doctor"},
{Name: "Ayushman", Country: "America", Profession: "Lawyer"}
)

Add a Vertical gallery control, select MyFirstCollection as the data source.

Search function in Power Apps

Step 2: On the + Insert tab, , from the Input section, select Text Input. Position the Text Input control to the right of the gallery.

Search function in Power Apps

Step 3: We can rename the Text Input control from TextInput1 to SearchInput.

Search function in Power Apps

Step 4: Set the Default property value to blank, i.e., “”.

Search function in Power Apps

Step 5: Set the Items property of the gallery control to the following powerapps formula.

PowerApps Formula

Search(MyNewCollection, SearchInput.Text, Name)

This would return all the rows where the Name column contained the value entered in the Text Input control which is renamed as SearchInput. Another useful behavior is if SearchInput is blank, meaning the user has not entered any data, then all the rows from our data source which is MyNewCollection, would be returned. This makes the Search function very powerful and easy to use.

Search function in Power Apps

Put the app in preview mode. And enter the value in the Text Input control and see the effect.

Search function in Power Apps

No result is available when we search the record according the Profession or Country column.

Search function in Power Apps

Step 6: The Search function can also be used to search across more than one column. We can add as many additional column names at the end of the expression. The following search function search across Name and Profession columns. Set this function to the gallery control.

PowerApps Formula

Search(MyNewCollection, SearchInput.Text, Name, Profession)

Note:

Search function in Power Apps

Put the app in preview mode, now we can search in the gallery according to the Name column and the Profession column.

Search function in Power Apps

We can Combine Filter and Search Function We can combine the Filter function and the Search function. For the Search function, the first parameter is the required and is a table of data. The Filter function returns a table of data. It means we can use the Filter function as a data source for our Search function.

Replace MyNewCollection with Filter(MyNewCollection, Country = "India") which will then make our expression look like this:

PowerApps Formula

Search(Filter(MyNewCollection, Country = "India"), SearchInput.Text, Name, Profession)

Additionally, if the control is blank, then all of the rows that were returned by the Filter function will be displayed.

2. Sharepoint as a Data Source

We can use the Search function with Sharepoint as our Datasource.

Important Note on Delegation The Search function is not delegable when using with Sharepoint as a Data source.

Put the following powerapps formula on the Items property of the Vertical gallery control.

PowerApps Formula

Search('Teachers Data', SearchInput_1.Text, ‘Teacher name’)

Here, ‘Teachers Data’ is the name of the sharepoint list. And 'Teacher name' is the name of the column in which we are going to search.

Note:

Search function in Power Apps

Put the app in preview and let’s try this function we can see that even the partial match records are also get by the Search function.

Search function in Power Apps