cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Filter gallery items

I'm new to PowerApps and i'm trying to filter a gallery with multiple TextInput fields. I am having trouble using the fields to filter the gallery. Currently i have 5 fields in the gallery (New, Old, Name,Locatoin,and email). How can i use five TextInput fields to be able to filter the gallery?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Champion
Community Champion

Re: Filter gallery items

Hi @rodieremix,

 

If I understand correctly, you are interested in the same solution about how to search when a field is blank. With all 4 conditions in the filter, things stop working. 

 

I formatted your formula for readibility:

SortByColumns(
    Filter('Activation Requests', 
        If(!IsBlank(TextSearchBox1),
            TextSearchBox1.Text in Client_x0020_Name_x0028_s_x0029_ 
            Or 
            TextSearchBox1.Text in Client_x0020_Number_x0028_s_x002,
        true) && 
        
        If(!IsBlank(PRSEmailVar),
            PRS_x0020_Email = PRSEmailVar,
            true
        ) && 
        
        If(!IsBlank(StatusVar),
            Setup_x0020_Status.Value = StatusVar,
            true
        ) && 
        
        If(!IsBlank(SuperVar),
            PRS_x0020_Supervisor.Email = User().Email,
            true
        )
    ),
SortVar, AscDesVar
)

 

I color coded the 4 conditions. It appears the red condition is problematic:

  • The Or operator can be used two ways.
    • You can wrap Or() around all of your conditions and separate them by a comma:

      If(!IsBlank(TextSearchBox1),
          Or(
              TextSearchBox1.Text in Client_x0020_Name_x0028_s_x0029_,
              TextSearchBox1.Text in Client_x0020_Number_x0028_s_x002
          ),
      true)
    • You can use || between two conditions:

      If(!IsBlank(TextSearchBox1),
          TextSearchBox1.Text in Client_x0020_Name_x0028_s_x0029_ || TextSearchBox1.Text in Client_x0020_Number_x0028_s_x002,
      true)
      Depending on what you're comparing in each condition, you may want to wrap individual conditions in parentheses so they do not interfere with one another. (I think you'll be okay this time, but greater than and less than don't play well with multiple conditions.)

      If(!IsBlank(TextSearchBox1),
          (TextSearchBox1.Text in Client_x0020_Name_x0028_s_x0029_) || (TextSearchBox1.Text in Client_x0020_Number_x0028_s_x002),
      true)

I would also recommend that you set User().Email to a variable, then use the variable in your filter. When you place User().Email into the filter raw, the app needs to figure out the user's email address for each record in the table which impacts performance--it is an odd behavior.

 

Please let me know if these two changes help.

 

Mr. Dang

 

_________________

Microsoft Employee
@8bitclassroom

View solution in original post

10 REPLIES 10
Highlighted
Community Champion
Community Champion

Re: Filter gallery items

Hi,

The way PowerApps works is that controls don't actively push data into the gallery. Instead the gallery looks at values in the TextInput controls to be filtered. So you would change the Items property of the gallery instead of using the properties of the TextInput controls.

 

Filter(datasource,
    New=TextInput1.Text &&
    Old=TextInput2.Text &&
    Name=TextInput3.Text &&
    Location=TextInput4.Text &&
    Email=TextInput5.Text &&
)

This means, "In your gallery, only show records from your datasource where the New column equals what's written in TextInput1.Text, the Old column equals what's written in TextInput2.Text, and so on..."

 

There's a few variations to this. Instead of the && symbol, you can use a comma for each condition since it's understood as "And." You can also create conditions for each condition. Meaning--maybe you don't want the datasource filtered by all 5 columns all the time. It's unlikely to yield many results that way. You could either use the Search function or more conditions.

 

Search:

Filter(datasource,
    If(!IsBlank(TextInput1.Text),New=TextInput1.Text,true) &&
    If(!IsBlank(TextInput2.Text),Old=TextInput2.Text,true) &&
    If(!IsBlank(TextInput3.Text),Name=TextInput3.Text,true) &&
    If(!IsBlank(TextInput4.Text),Location=TextInput4.Text,true) &&
    If(!IsBlank(TextInput5.Text),Email=TextInput5.Text,true) &&
)

This means, "In your gallery, only show records from your datasource where conditions are true for a column when its corresponding TextInput field is not blank." Or in literal terms, "Filter the datasource to show records that return true--If TextInput1 is not blank, then check the New column to see if it equals what's typed in TextInput1."

 

The Search() function understands that when the TextInput is blank, it won't try to filter, so it can be easier. You would need to nest several of them so that what you type into each TextInput is searched in the corresponding column.

 

However, if you want to really simplify things, the Search function can be very efficient in terms of coding and user interface. You could reduce the number of TextInput fields to just one. Using the Search function, anything that is typed into that one TextInput field can be compared against as many columns as you would like. To see an example, you could create a new app straight from a datasource and PowerApps will use this setup in its basic template.

 

Here's an example:

Search(datasource,
    TextInput1.Text,

    "New",
    "Old",
    "Name",
    "Location",
    "Email"
    
)

This means, "In your gallery, show all records from your datasource where whatever you type in TextInput1 matches any of the 5 columns."

 

Let me know which method you go with.

Microsoft Employee
@8bitclassroom
Highlighted
Frequent Visitor

Re: Filter gallery items

Hi,

 

The first example you gave me seemed to work, but like you said it's too specific of a search. The Second example is more what i'm looking for. So far this is what i have.

 

Filter('Main Info_1',If(!IsBlank(TextInput1.Text),Old_x0020_Commodity=TextInput1.Text,true),If(!IsBlank(TextInput2.Text),New_x0020_Commodity=TextInput1.Text,true))

 

However, when i type anything into either of the textinputs i get a blank result. I cant,t figure out what is causing this issue.

 

Thanks for the help!

 

Highlighted
Frequent Visitor

Re: Filter gallery items

I also got the blue dot error message " Part of this filter formula cannot be evaluated remotely due to service limitations".

Highlighted
Community Champion
Community Champion

Re: Filter gallery items


@wnboothBW wrote:

Filter('Main Info_1',If(!IsBlank(TextInput1.Text),Old_x0020_Commodity=TextInput1.Text,true),If(!IsBlank(TextInput2.Text),New_x0020_Commodity=TextInput1.Text,true))

 

However, when i type anything into either of the textinputs i get a blank result. I cant,t figure out what is causing this issue.

 

Thanks for the help!

 


Formatted:

Filter('Main Info_1',
    If(!IsBlank(TextInput1.Text),Old_x0020_Commodity=TextInput1.Text,true),
    If(!IsBlank(TextInput2.Text),New_x0020_Commodity=TextInput1.Text,true)
)

Did you want both of them to look at TextInput1? I assume that's a typo that might be causing your issue.

 

Since you are getting the blue dot, I recommend the third method where you cut down the textinput boxes and use Search to check that one box against your chosen columns.

Microsoft Employee
@8bitclassroom
Highlighted
Frequent Visitor

Re: Filter gallery items

That was a typo on my end, it still doesnt work when there are two different input boxes. 

 

The problem with using the search function is that i cannot get a specific enough result that i am looking for.

Highlighted
Community Champion
Community Champion

Re: Filter gallery items

I haven't tried nested Search functions, so I'm not sure if they delegate. If you keep the 5 TextInput fields, you might be able to nest each of them.

 

Search(
    Search(
        Search(datasource,"column1",TextInput1.Text),
    "column2",TextInput2.Text),
"column3",TextInput3.Text
)

Something like that.

If you try that, let me know if the blue dot appears.

Microsoft Employee
@8bitclassroom
Highlighted
Advocate III
Advocate III

Re: Filter gallery items

Hi @mr-dang,

 

I know this is an old thread but I've found it very helpful. I have run into an issue though and I am wondering if you have any input on what I could do to resolve it. I built my gallery filters based on your post, here's the function:

 

SortByColumns(Filter('Activation Requests', If(!IsBlank(TextSearchBox1),TextSearchBox1.Text in Client_x0020_Name_x0028_s_x0029_ Or TextSearchBox1.Text in Client_x0020_Number_x0028_s_x002,true) && If(!IsBlank(PRSEmailVar),PRS_x0020_Email = PRSEmailVar,true) && If(!IsBlank(StatusVar),Setup_x0020_Status.Value = StatusVar,true) && If(!IsBlank(SuperVar),PRS_x0020_Supervisor.Email = User().Email,true)),SortVar, AscDesVar)

 

Here is the issue I am running into. There are 4 potential items to filter on (TextSearchBox1, PRSEmailVar, StatusVar, and SuperVar). The filter functionality itself works perfectly. When my variables are set or the search box is populated, the gallery reflects the items I would expect it to. However, with all 4 potential items built into the function, the filter does not behave as expected. When I go to navigate to a specific item, it always goes to the first item in the list. Then if I go back and try to navigate to the item, it works as expected. 

 

Here's where I'm really confused. If I take out any one of these conditions, I don't get the same issue. It always navigates to the correct item the first time. At first I thought it was related to the TextSearchBox1 parameter, but when I left that one in and removed the "SuperVar" parameter, it worked as desired. So it seemingly works fine at 3 items, but not 4. 

 

Hopefully you see this and can assist. Please let me know if you need any additional details. Thank you!

Highlighted
Community Champion
Community Champion

Re: Filter gallery items

Hi @rodieremix,

 

If I understand correctly, you are interested in the same solution about how to search when a field is blank. With all 4 conditions in the filter, things stop working. 

 

I formatted your formula for readibility:

SortByColumns(
    Filter('Activation Requests', 
        If(!IsBlank(TextSearchBox1),
            TextSearchBox1.Text in Client_x0020_Name_x0028_s_x0029_ 
            Or 
            TextSearchBox1.Text in Client_x0020_Number_x0028_s_x002,
        true) && 
        
        If(!IsBlank(PRSEmailVar),
            PRS_x0020_Email = PRSEmailVar,
            true
        ) && 
        
        If(!IsBlank(StatusVar),
            Setup_x0020_Status.Value = StatusVar,
            true
        ) && 
        
        If(!IsBlank(SuperVar),
            PRS_x0020_Supervisor.Email = User().Email,
            true
        )
    ),
SortVar, AscDesVar
)

 

I color coded the 4 conditions. It appears the red condition is problematic:

  • The Or operator can be used two ways.
    • You can wrap Or() around all of your conditions and separate them by a comma:

      If(!IsBlank(TextSearchBox1),
          Or(
              TextSearchBox1.Text in Client_x0020_Name_x0028_s_x0029_,
              TextSearchBox1.Text in Client_x0020_Number_x0028_s_x002
          ),
      true)
    • You can use || between two conditions:

      If(!IsBlank(TextSearchBox1),
          TextSearchBox1.Text in Client_x0020_Name_x0028_s_x0029_ || TextSearchBox1.Text in Client_x0020_Number_x0028_s_x002,
      true)
      Depending on what you're comparing in each condition, you may want to wrap individual conditions in parentheses so they do not interfere with one another. (I think you'll be okay this time, but greater than and less than don't play well with multiple conditions.)

      If(!IsBlank(TextSearchBox1),
          (TextSearchBox1.Text in Client_x0020_Name_x0028_s_x0029_) || (TextSearchBox1.Text in Client_x0020_Number_x0028_s_x002),
      true)

I would also recommend that you set User().Email to a variable, then use the variable in your filter. When you place User().Email into the filter raw, the app needs to figure out the user's email address for each record in the table which impacts performance--it is an odd behavior.

 

Please let me know if these two changes help.

 

Mr. Dang

 

_________________

Microsoft Employee
@8bitclassroom

View solution in original post

Highlighted
Advocate III
Advocate III

Re: Filter gallery items

@mr-dang That took care of it, thank you so much! That's also good to know about User().Email, I use that quite a bit so I'll remember that in the future. Thanks again!

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (4,104)