#PowerApps Tips : Ambiguous search with multiple condition

As a part of design process of PowerApps or support in Community, I often see people want to put search functionality with multiple conditions like status of record, employee name, and some IDs.
Simple list app (templates in PowerApps studio) only has single search condition and Gallery items would be filtered to contain search string.
In this post, I quickly explain how to build list apps having ambiguous search with multiple conditions.

#Setup
To simplify the situation, I assume 1 list with 3 fields like;

|Employee ID  |Employee Name  |Job Title  |
|---|---|---|
|E123456  |Tom, Hanks  |Manager|
|E123333  |Louis, Litt  |Director  |
|E234567  |Hillary, Clinton  |Director  |
|E987654  |Mike, Ross  |VP  |

Here, Job Title is choice field, Employee ID and Employee Name are single text.
We can add gallery control with above data in your screen, and I don't set any search condition to Gallery yet, only add 2 TextInput and 1 Dropdown.
![image.png](https://qiita-image-store.s3.amazonaws.com/0/202779/5cb112d3-b2c9-d550-10cd-f807a934edae.png)


Hereafter, I would explain how to reduce records by putting Search functions into Gallery Items. 

#Using Search() function
From description about [Search function](https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-filter-lookup), Search function is ambiguous/contains search and search condition(formula) is single.
(i.e., You can search "123" in EmployeeID, but cannot "123" in EmployeeID & "Tom" in Employee Name)
>The Search function finds records in a table that contain a string in one of their columns. The string may occur anywhere within the column; for example, searching for "rob" or "bert" would find a match in a column that contains "Robert". Searching is case-insensitive. 

To realize multiple search condition using Search function, you can add nested Search functions into your Gallery Items:

```Gallery.Items
Search(
    Search( 
        Search( 
            //Search condition 1: Search by Job title based on Dropdown selected item
            Table,
            Dropdown1.Selected.Value,
            "Job Title"
        ),
        //Search condition 2: Employee Name by input text
        TextInput1_1.Text,
        "Employee Name"
    ),
    //Search condition 3: Employee ID by input text
    TextInput1.Text,
    "Employee ID"
)
```
Then we get reduced records based on multiple conditions
![image.png](https://qiita-image-store.s3.amazonaws.com/0/202779/354b47c9-683d-3abc-0c43-ce0102cc6e05.png)

This is one example to apply multiple search condition to Gallery records.

#Using Filter() function
Filter function is bit different with Search function, it has capability for multiple formula/condition.
But you would encounter difficulty for "ambiguity" of search condition, usually we set formula like
```TextInput1.Text='Employee ID'```. This returns record ONLY when input text exactly match field value.
>Filter( Table, Formula1 [, Formula2, ... ] )

>Table - Required. Table to search.
>Formula(s) - Required. The formula by which each record of the table is evaluated. The function returns all records that result in true. You can reference columns within the table. If you supply more than one formula, the results of all formulas are combined with the And function.

So, how we can keep ambiguity (meaning partially match/contains).
You can use IN statement to ensure ambiguity.

```Gallery.Items
Filter(
    Table,
    TextInput1.Text in 'Employee ID',
    TextInput1_1.Text in 'Employee Name',
    Dropdown1.Selected.Value in 'Job Title'
)
```
This expression returns record same as "nested search".


#Conclusion
Search() function is powerful and flexible if you have only 1~2 search condition, however,
when search condition becomes more complex, Item property would nested nested nested .... search function.
When you apply 3 or more search condition to reduce/find records, it would be better to use Filter & IN statement.

**Enjoy PowerApps!!**