PowerApps Search Function + How to use with example
In this Power Apps Tutorial, We will discuss what is the PowerApps Search function, it’s syntax, how to use the Power Apps search function in a canvas app. We will see how to apply a search box in PowerApps.
We will also see how to search for items from the SharePoint list using the PowerApps search function.
Also, We will see how to use the Search function in a Vertical Gallery Control and how can you do multiple searches.
Also, We will discuss what is the PowerApps Search Delegation and how to use the Search function in a Drop-down control in Power Apps.
Power Apps Search Function
We can use the PowerApps search function to find records from a table that contains a string value in any of the columns. The search string can be presented anywhere in the columns.
PowerApps search function returns the same columns which are presented in the table from where you searching.
The table should contain columns which are having a Text or String value. Apart from a Text value, it will not take any other column value like Number, Choice, Picture, Hyperlink, etc.
Also, a Lookup column does not work with the Power Apps Search function at all.
The Search function uses a single string to match instead of a formula. That’s why this Powerapps Search function is case-insensitive in nature.
PowerApps search function syntax
Below represents the Power Apps Search Function Syntax:
Search( Table, SearchString, Column1 [, Column2, ... ] )
Where,
- Search = It is the Power Apps function which helps to search.
- Table = Specify the Table name that is used to search.
- SearchString = Specify the string to search for. It will be returned to all the records if there will be a blank or an empty string.
- Column(s) = Specify the column names those you want to search from the table. Whatever you are passing the columns, it should be a Text column and the column names should be strings which is in double-quotes. The specified column name should be static and cannot be calculated with a formula.
Use PowerApps Search Function in a Vertical Gallery Control
We can use the Search function in a Vertical Gallery control, follow the below steps:
If you are new to PowerApps, then check out few article on Create a canvas app from Excel in Power Apps (Step by Step tutorial) and also you can check How to Create a Canvas app from SharePoint List in Power Apps.
Step-1:
First of all, On your PowerApps Screen, Add a Blank Vertical Gallery Control (Insert -> Gallery -> Vertical). Then connect a Data Source as SharePoint (As my records are present in a SharePoint List) as shown below.
Step-2:
Select or Enter your SharePoint site or URL and Connect it. Then choose your SharePoint List (Event Registration Details) and hit on the Connect button.
NOTE:
Not only you can use the Data source like SharePoint, But also, you can use the Data source as Excel (Import from Excel).
Step-3:
In the below screenshot, you can see all the records are retrieved from the SharePoint List. Here, your Item property should be your SharePoint List name (‘Event Registration Details‘).
Select the Gallery and go to the Properties pane. Select the Layout as “Title, subtitle, and body“. Edit the fields and add the columns as per your choice.
Step-4:
Now to search the fields from the PowerApps vertical gallery, we need to add a search bar on the top of the Gallery. For that, Go to Insert -> Text -> Add Text Input as shown below.
The Text input control will insert and it will show the default value as Text. Just remove the Default value.
Instead of the Default value, We will add a HintText value as “Search on Name”. instead of Name, you can provide anything like “Search on Profile”, “Search on Department”, “Search on Organization” etc.
The benefit of adding the HintText in the text control is, it will look like a Search box and more attractive.
Step-5:
Add a Search icon (Insert -> Icons ->Search) near to the Search box. So that it will look like a perfect Search box to find out any fields like the below screenshot.
The OnSelect Property of the Search icon should be false.
Step-6:
Select the Vertical Gallery control and apply the below Search function formula on its Items property as:
Items = Search('Event Registration Details', SearchBox.Text, "Title")
Where,
- Search = This is the function used to find out the record from a table.
- ‘Event Registration Details‘ = This is the SharePoint List name.
- SearchBox.Text = This is the Text input control name that I have added for searching.
- “Title” = It is the SharePoint List column name which is used to search in the search box.
Step-7:
Just Preview (F5) or run the app. Search by Title or Name in the Search bar, then you can see it will search by the particular name and give you the appropriate result as shown below.
PowerApps search function multiple conditions
Suppose, you want to do multiple conditions searches using the Search function in PowerApps. That means, if you want to search by Name, also you want to search by Organization or by Email Address, then you can do it.
But, all the fields should contain only the String or Text value otherwise it will not allow us to search and an error will appear on the screen.
In this case, you can apply the below formula on the Gallery Items property as:
Items = Search('Event Registration Details', SearchBox.Text, "Title", "Organization", "EmailAddress")
Where,
“Title”, “Organization”, “EmailAddress” = These are the SharePoint list fields that contains only the Text value.
Once you will preview and search by name, by Organization or by Email Address, then it will give you the perfect result as like the below screenshot.
NOTE:
Some times, you may get the Search function invalid argument error while using the Search function with multiple conditions in Power Apps. You can overcome this type of issue by using the below Power Apps article:
The function Search has some invalid arguments in PowerApps
Search Delegations in PowerApps
You can see, there will be a warning suggestion is visible on the top of the gallery. This is known as the Delegation suggestion.
You will get this Search Delegation suggestion when your data in the data source exceeds 500 records and a function can’t be delegated. In this case, the Power Apps may not able to get your data and may give the wrong results.
You can use any Data source and formula if you are working with the small data sets which are fewer than 500 data or records.
Solution:
To get over from this Delegation problem, We need to change the Value from the Power Apps Advanced settings.
This can be easily changed by using the File tab -> Settings -> Advanced settings -> Value -> make the Value as 500 to 2000 as shown in the below screenshot.
The value will take in between 1 to 2000 only. Once it exceeds 2000, then it won’t take.
Also, you can do another thing. If your data in the Data set is having more than 500 value, then you need to break the data from data sets in an equal manner. After that, make individual data set and each data set value should be 500.
PowerApps Search using a Drop-Down Input Control
You can use the PowerApps Search function using a Drop-down control. On your Power Apps screen, Add a Dropdown control (Insert -> Input -> Dropdown) as shown below.
Select the Drop-down input control and apply the below formula on it’s Items property as:
Items = Search('Event Registration Details', SearchBox.Text, "Title", "Organization", "EmailAddress")
When you will preview the app, then you cannot able to see anything in the drop-down control as shown below.
The reason behind this thing because the above Search formula is returning all the columns from the SharePoint List (Event Registration Details).
To show a particular column value, We need to use the ShowColumn function.
Apply the below formula on the Drop-down Items Property as:
Items = ShowColumns(Search('Event Registration Details', SearchBox.Text, "Title", "Organization", "EmailAddress"),"Title")
Not only you can use the Show Column value as “Title”, But also, you can use any other Text or String column like “Organization”, “EmailAddress”, etc.
Now preview or run the app and click on the drop-down. You can see all the Titles or Names as below screenshot.
Similarly, When you will search the name on the Search box, it will reflect in the Dropdown bar. Suppose, you are searching a name by “Sania”, then the name “Sania” is reflecting in the Dropdown bar as shown below.
PowerApps search and filter combined
Next, we will see what does the mean of PowerApps search and filter combined.
- Filter with Search together in PowerApps is known as PowerApps search and filter combined. That means, to get a result, we can search and as well as filter the gallery.
- In the below screenshot, you can see there is a text input control and a gallery control. Here I need to put search so that users can find specific numbers while app is retrieving certain fields through a Sharepoint List or a Table.
- when I am searching the Employee ID in the text box, then the gallery is filtering and displaying the result. And even if I am not seraching anything in the text box, then also the gallery is filtering and appearing with the same result.
- So this is the thing, at a time you can search and as well as filter the gallery to display the result. Follow the below code to do this.
- Select the gallery and apply the below formula on its Items property as:
Items = Search(
AddColumns(
Filter(
'Employee Onboarding',
'Employee ID' = 102
),
"Result",
Text('Employee ID')
),
txtEnterID.Text,
"Result"
)
Where,
- AddColumns = PowerApps AddColumns is a type of function that helps to add a column to a SharePoint list or a table. To know more details about this function, please refer to this complete tutorial: PowerApps AddColumns Function with Examples
- ‘Employee Onboarding‘ = Specify the SharePoint list name
- ‘Employee ID‘ = SharePoint Number field name
- “Result” = Specify the new column name
- txtEnterID = Text input control name
NOTE:
You need to ensure to set the “Data row limit” option to maximum value — 2000 within General settings of App settings of your app.
This is how to work with PowerApps search and filter combined.
Read: Power Apps Search SharePoint List Examples
PowerApps search button
Do you need to create a PowerApps search button that will display only the Yes value while a user clicks on it? It’s very simple to create a button and display the values in PowerApps.
- The below image represents a Button control and a gallery control. If you will click on the button (Click to show Approve items), then the gallery will display all the records those are approved. And again when you will tap on the button, then the gallery will revert back to the previous records.
- So this is my SharePoint list that I have used in the app named Products. And these are the below items that are used in the gallery control. Now I would like to view all the approved items in the gallery on the button click.
- To do this, we need to create a context variable on the OnSelect property of the button control:
OnSelect = UpdateContext({Filtered: Not(Filtered)})
Where,
Filtered = Context variable name
- Next, apply the below formula on the gallery’s Items property as:
Items = If(
Filtered,
Filter(
Products,
Status.Value = "Approved"
),
Products
)
Where,
- Filtered = Context variable name
- Products = SharePoint list name
- Status = This is a Sharepoint choice column. So we need to mention this field name with a .Value
- “Approved” = Provide the choice value that you want to filter in the gallery
Refer to the below screenshot.
That’s what it does in the app. Now you can perform it as per your choice.
- Suppose if you want the operation to be “one way” (i.e. once you apply the filter it sticks forever), then you need to change the formula on the button’s OnSelect property:
OnSelect = UpdateContext( { Filtered: true } )
This is the search button in PowerApps.
Also, read: PowerApps Search User
PowerApps search data table
In this topic, we will see how we can search the Data table control in PowerApps.
The below scenario explains how you can search and filter the data table control based upon a Dropdown menu in PowerApps.
- I have a SharePoint list named TSInfo Attachments. This list has some below columns:
- ID = By default it is a Number type column in the SharePoint list
- Title = This is also a by default column in the list
- Attachment Types = This is the name of SharePoint Choice column
- Book Author = People picker column name
- IsReceived = Yes/No field
- IsSatisfied = Yes/No field
- Now in the app, there is a Dropdown control and a Data table control. The dropdown menu has the choice values those are retrieved from the SharePoint choice column (Attachment Types).
- When a user will select any choice value from the dropdown control, then the data table will filter and display only those specific searchable records.
- For example, as I selected the Document type as PDF, so the data table displayed all the records those are related to PDF only as shown below.
- To do so, select the dropdown menu and set its Items property as:
Items = Choices('TSInfo Attachments'.'Attachment Types')
- Next, apply the below code on the Data table’s Items property as:
Items = Filter(
'TSInfo Attachments',
ddSelectDoc.SelectedText.Value in 'Attachment Types'.Value
)
Where,
- ddSelectDoc =Dropdown control name
- ‘Attachment Types’.Value = As this is a SharePoint choice field, so we need to specify this field with a .Value parameter
Refer to the below screenshot.
This is how to work with the PowerApps search data table.
Also read: PowerApps SharePoint Lookup Column + PowerApps Dropdown Example
PowerApps search exact match
Do you want to show only if the search is an exact match in PowerApps? Yes, you can do it very easily. Check out this link to get more details: PowerApps search exact match
PowerApps highlight search text
Do you know what is PowerApps highlights search text and how you can achieve it? Here we will see how to highlight search terms in the search result in PowerApps.
- Refer to the below screenshot. you can see there is a Text input control and a gallery control. In the first image, when a user searched the Book Name as Power, then in the gallery, nothing happened.
- In the second image, when a user searched the Book Name as Power, then the specific searching word got highlighted in the gallery control. This is known as highlight search text in PowerApps.
- So whatever the word a user will search in the search box, that specific word will get highlight in the gallery control as shown below.
- To make this possible, we will use the HTML text control inside the gallery. Because this highlight thing you can achieve in the HTML text control only.
- Here, the Items property of the gallery contains the below code:
Items = Search(
'TSInfo Attachments',
txtSearchBook.Text,
"Title"
)
Where,
- ‘TSInfo Attachments‘ = SharePoint list name
- txtSearchBook = Text input control name where a user will search the book name
- “Title” = SharePoint text column
- To achieve this need, select the main section of the gallery and replace a HTML text instead of the label control.
- To replace it, go to Insert tab -> Text -> HTML text and then the HTML control will add in that gallery section as like the below screenshot.
- Next, select the HTML text control and apply the below code on its HtmlText property as:
HtmlText = "Book Name: " & Substitute(
ThisItem.Title,
txtSearchBook.Text,
"<font color=Lightgreen>" & txtSearchBook.Text & "</font>"
)
Where,
- “Book Name: ” = This is the text that will display in the HTML text control
- Substitute = PowerApps Substitute function helps to identify the string to replace by matching a string. To read more details, refer to this complete tutorial: PowerApps Replace Function with examples
- Title = SharePoint Text field
- txtSearchBook = Text input control name
This is how to work with highlight search text in PowerApps.
PowerApps Search Integer
Do you want to search and filter the records by an Integer in PowerApps? Follow the below scenario to get some ideas that how you can use it.
- The below screenshot represents, when you do not search anything in the search box, then the gallery will appear with all the SharePoint records. When a user will search any employee ID, then the gallery will filter and display that specifc searchable record details as shown below.
- The below screen represents the Sharepoint List named Employee Onboarding. This list has some different types of columns like single line of text, Number, Choice, etc.
- There is an Employee ID field with the Number data type. In PowerApps, I would like to search and filter the gallery based upon this Employee ID column.
- To workwround with this, select the gallery control and set the below code on its Items property as:
Items = Filter(
'Employee Onboarding',
Or(
StartsWith(
Title,
txtEnterEmpID.Text
),
StartsWith(
'Employee ID',
Value(txtEnterEmpID.Text)
)
),
"Date"
)
Or, you can apply the below formula:
Items = Filter(
'Employee Onboarding',
Or(
StartsWith(
Title,
txtEnterEmpID.Text
),
StartsWith(
Text('Employee ID'),
txtEnterEmpID.Text
)
),
"Date"
)
Where,
- ‘Employee Onboarding‘ = SharePoint List name
- StartsWith = PowerApps StartsWith function helps to test whether a text string begins with another. To read more details about this function, refer to this complete post: PowerApps StartsWith and EndsWith Functions
- Title = SharePoint single line of text field
- txtEnterEmpID = Text input control name where the user will search any employee ID
- ‘Employee ID‘ = SharePoint Number field
This explains how to work with PowerApps Search Integer.
PowerApps Search Limit
- As we know, Every data source has some limits in PowerApps. Similarly, the PowerApps Search function has also a certain limit i.e. 500.
- If you have more than 500 items in your data source, then you can not get those items after 500. Then in this case, you will get some warning message in the app which is known as PowerApps Delegation issues.
- To overcome this issue, what are the instructions you need to follow, everything you will get to know from the provided link: PowerApps Search Limit
PowerApps listbox search
Suppose you want to search and filter the gallery records based upon the PowerApps Listbox selection, then check out the below simple scenario.
- In the below image, you can see there is a List Box control, and a Gallery control. The list box contains all the values from a SharePoint Choice field.
- Now what I would like to do is, when a user will select any value from the list box, then the gallery will filter based upon the selected value.
- For example, I selected the value as PDF from the list box, then the gallery filtered and displayed only the PDF related record details as shown below.
- This below represents the SharePoint list named TSInfo Attachments. This list has a Choice field called Attachment Types. I want all the choice values from this field will appear in the PowerApps list box control.
- To do so, insert a List box and set its Items property to the below code:
Items = Choices('TSInfo Attachments'.'Attachment Types').Value
As the Attachment Types field is a SharePoint Choice field, that’s why we need to write the formula with a .Value parameter.
- Then, we will create a context variable on the List box’s OnSelect property as:
OnSelect = UpdateContext({vSelectedItems: lbSelectDocType.Selected.Value})
Where,
- vSelectedItems = Specify the Context variable name
- lbSelectDocType = List box control name
- Now select the gallery control and apply the below formula on its Items property as:
Items = Filter(
'TSInfo Attachments',
'Attachment Types'.Value in vSelectedItems
)
Where,
- ‘TSInfo Attachments’ = SharePoint list name
- ‘Attachment Types’.Value = SharePoint Choice field
- vSelectedItems = Context variable name that you have created before
Refer to the below screenshot.
This is how to work with PowerApps Listbox Search.
PowerApps search multiple words
Do you want to search with multiple keywords and filter the gallery control in PowerApps? Check out the below simple scenario that how you can achieve it.
- In the app, insert a Text input control, a button control (Click Me), and a gallery control as like the below screenshot. So when a user will click on the button, then a data collection will create.
- When the search box is empty, then the gallery will display with all the collection records. But when the user will search one or more keywords in the search box, then the gallery will filter according to that specific searchable keyword.
- To achieve this, first we will create a PowerApps Collection on the button onclick. Select the Button (Click Me) and write the below code on its OnSelect property as:
OnSelect = ClearCollect(
colEmpDetails,
"Shane",
"TSInfo202",
"FINANCE",
"Casual Leave"
)
Where,
- ClearCollect = PowerApps ClearCollect function is a type of function that removes all the records from a collection. And then it adds a different set of records to the same collection. To read more details, refer to this complete tutorial: Create Collection from SharePoint List in PowerApps
- colEmpDetails = Specify the created collection name
- “Shane“, “TSInfo202“, etc. = These are the records that will store in the collection
- Next, apply the below formula on Gallery’s Items property as:
Items = If(
IsBlank(txtSearchWords.Text),
RenameColumns(
colEmpDetails,
"Value",
"Result"
),
Distinct(
Ungroup(
ForAll(
Filter(
Split(
Lower(txtSearchWords.Text),
","
),
!IsBlank(Result)
),
Filter(
colEmpDetails,
!IsBlank(
Find(
TrimEnds(Result),
Lower(Value)
)
)
)
),
"Value"
),
Value
)
)
Where,
txtSearchWords = Text input control name
- Save, Publish, and then Preview the app. Tap on the button (Click Me) and you can see the collection created and display all the values in the gallery. Now search some keywords in the search text box, you can able to see the filtered result in the gallery.
This explains how to work with search multiple words in PowerApps.
PowerApps search on button click
Do you want to search and filter the record with the click of a button? Yes, you can do it very easily. Refer to the below example.
- There is a Text input control, a Button control (Enter), and a Gallery control. A user will search the Product name in the search box, and then tap on the button. Once the user click on it, the gallery will filter and display with all searchable related record details as shown below.
- To achieve this, you need to create a context variable on the button’s OnSelect property as:
OnSelect = UpdateContext({searchTerm: txtSearchTitle.Text})
Where,
- searchTerm = Context variable name
- txtSearchTitle = Specify the text input control name
- Next, select the gallery control and apply the below code on its Items property as:
Items = Search(
Products,
searchTerm,
"Title"
)
Where,
- Products = SharePoint list name
- searchTerm = Context variable name that you have created on the button
- “Title” = SharePoint text column
- Save, Publish the app. Now Preview the app and search any product title in the search box and then click on the Enter button. Then you can view the filtered result in the gallery as shown above.
This is how to work with PowerApps search on button click.
PowerApps search box
In this topic, we will see how to work with the PowerApps Search box.
- I have a SharePoint list named Blog Sites. This list has these many below columns with different data types as:
- Title = By default this is a single line of text field
- Site URL, Site Rank, Site Work = These all are single line of text fields
- In the below screenshot, you can see there is a gallery control and a text input control. Now what I want to do is, when a user will search the blog title in the search box, then the gallery will filter and display with the filtered record details.
- For example, as I searched the title SharePoint, so the gallery filtered and appeared with SharePoint details as shown below.
- To work with this, select the gallery control and apply the below formula on its Items property as:
Items = SortByColumns(
Filter(
'Blog Sites',
StartsWith(
Title,
txtEnterTitle.Text
)
),
"SiteWork"
)
Where,
- ‘Blog Sites’ = SharePoint list name
- Title = Specify the Sharepoint field name that you want to search in the text box
- txtEnterTitle = Text input control name
- To display the Title field in the gallery, make sure to set the Text property of the label inside the gallery as:
Text = ThisItem.Title
This is how to work with the search boxes in PowerApps.
PowerApps reset search box
Do you want to reset or clear the search text box in Power Apps? You can reset the text box very easily by a single formula itself.
- In apps what happens is, suppose you are searching something in a search text box and then navigating to the other screen for some purposes.
- Again when you came back to the previous screen, you can able to see the same search keyword that you were searching before. But you do not need that. Instead of that keyword, you want to reset the search box in the app.
- To workaround with this, I got two things or formulas that you can try out and get it done.
Example – 1:
- To achieve this, you can insert a Button control (named as RESET) and set its OnSelect property to the below code as:
OnSelect = Reset(txtBtnReset)
Where,
txtBtnReset = Text input control name
- Now save and preview the app. Search any keyword in the search box and then tap on the RESET button. You can see the searching word will clear from the text box.
Example – 2:
In another way, we can try out the below codes to clear the search box in PowerApps.
- First, we need to create a context variable on the Button’s OnSelect property as:
OnSelect = UpdateContext({ClearSearch: true});
UpdateContext({ClearSearch: false})
Where,
ClearSearch = Context Variable name
- Next, select the search input box and make its Clear property to false as shown below.
Clear = false
Here, you need to make sure you don’t have two buttons to clear the control in the app.
- At last, go to the Reset property of the text input control and set the created context variable on it.
Reset = ClearSearch
- Now save and preview the app. Search any keyword in the search box and then tap on the RESET button. You can see the searching word will clear from the text box.
These are the two ways where you can reset the search box in PowerApps.
PowerApps Search Date range
In this topic, we will discuss how to Search the Date range in PowerApps. The range in between two dates is known as the Date range. Now to work with the date range in PowerApps, check out the below scenario.
- In this example, I have a SharePoint List named Products that is having different types of fields. Now in PowerApps, I would like to create a gallery that will show the last 30 days of product sales details.
- When a user will select any of the product from the dropdown control, then the gallery will filter and display any products sold to the list with that product type.
- To achieve this, select the gallery and set its Items property to the below code:
Items = Filter(
Products,
Title = ddSelectProduct.Selected.Title && 'Sales Date' >= DateAdd(
Today(),
-30,
Days
)
)
Where,
- Products = SharePoint List name
- Title = SharePoint text field
- ddSelectProuct = Dropdown control name where a user can select any product
- ‘Sales Date‘ = SharePoint Date field name
Refer to the below screenshot.
This is how to work with PowerApps Search Date range.
PowerApps Count Search Results
Here in this topic, we will see what is PowerApps count search results.
- As we know, we can count all the items those are available in the PowerApps Gallery or Data table control. But instead of that, if you want to count the total records that are filtered in the gallery or data table control, then what and how the exact formula will apply. To do this, follow the below example.
- In the below image, you can see, when I searched the product as Laptop, then the gallery filtered and displayed the search related result details. Here, I wanted to count all the filtered records in the gallery.
- As the gallery filtered result count is 4, so the count result is displayed in the label control as shown below.
- To work around with this, apply the below code on the data table’s Items property as:
Items = Filter(
Products,
Title = txtSearchProduct.Text
)
Where,
- Products = SharePoint List Name
- Title = Sharepoint text field
- txtSearchProduct = Text input control name
- Next, select the label and set the below formula on it’s Text property as:
Text = "Total Search Result: " & CountIf(
Products,
Products[@Title] = txtSearchProduct.Text
)
Where,
- “Total Search Result: ” = This is the string that will display in the label control
- CountIf = PowerApps CountIf function helps to count the total number of items or records in a table that are true. To read more details about CountIf function, refer to this post: PowerApps CountIf Function with Examples
Refer to the below image.
This is how to work with PowerApps Count Search Results.
PowerApps search combobox
Do you want to search any record by using the PowerApps Combo Box control? Check out the below example that how you can work with it.
- As you can see there is a Combo box control and a Gallery control. When you will search the customer name (s) from the combo box, then all the search-related records will appear in the gallery control.
- To workaround with this, set the below code on Combo box’s Items property as:
Items = Products.'Customer Name'
Where,
- Products = SharePoint List name
- ‘Customer Name’ = SharePoint single line of text column
- Next, apply the below formula on gallery’s Items property as:
Items = Filter(
Products,
'Customer Name' in ComboBox2.SelectedItems
)
Where,
ComboBox2 = Specify the name of the combo box control
This is how to work with PowerApps search Combobox.
No comments:
Post a Comment