Michelle
Michelle

Reputation: 549

Filter Powerapps Gallery by Filters or Search Bar

I have a gallery that I want users to be able to filter by either 3 unique filters (when one is selected the other 2 are automatically set to false) or by a search box.

I have the following code within my 3 filter buttons, which works to filter the gallery

Button 1 - UpdateContext({FilterbyAA:!FilterbyAA; FilterbyBB:false; FilterbyCC:false})
Button 2 - UpdateContext({FilterbyBB:!FilterbyBB; FilterbyAA:false; FilterbyCC:false})
Button 3 - UpdateContext({FilterbyCC:!FilterbyCC; FilterbyAA:false; FilterbyBB:false})

In my gallery I have the following code

If(
  FilterbyAA=true;
    Filter(EVENTDETAILS;TYPE="Once Off";PILLAR.Value="AA"); 
  FilterbyBB=true;
    Filter(EVENTDETAILS;TYPE="Once Off";PILLAR.Value="BB");
  FilterbyCC=true;
    Filter(EVENTDETAILS;TYPE="Once Off";PILLAR.Value="CC");
  Filter(EVENTDETAILS;TYPE="Once Off")
)

Could someone please tell me how I change this to say that if anything is entered into the search box, it should clear the filters and search by the search box entry instead?

I've tried the below but it doesn't work (the search does but not the filters)

If(Connection.Connected;Filter(EVENTDETAILS; StartsWith(EVENTNAME; SearchBox.Text));
    If(
      FilterbyAA=true;
        Filter(EVENTDETAILS;TYPE="Once Off";PILLAR.Value="AA"); 
      FilterbyBB=true;
        Filter(EVENTDETAILS;TYPE="Once Off";PILLAR.Value="BB");
      FilterbyCC=true;
        Filter(EVENTDETAILS;TYPE="Once Off";PILLAR.Value="CC");
      Filter(EVENTDETAILS;TYPE="Once Off")
    )

Upvotes: 0

Views: 1036

Answers (1)

Ganesh Sanap - MVP
Ganesh Sanap - MVP

Reputation: 2218

Try using this formula:

If(
    IsBlank(SearchBox.Text);    
    If(
        FilterbyAA=true;
        Filter(EVENTDETAILS;TYPE="Once Off";PILLAR.Value="AA"); 
        FilterbyBB=true;
        Filter(EVENTDETAILS;TYPE="Once Off";PILLAR.Value="BB");
        FilterbyCC=true;
        Filter(EVENTDETAILS;TYPE="Once Off";PILLAR.Value="CC");
        Filter(EVENTDETAILS;TYPE="Once Off")
    );
    Filter(EVENTDETAILS; StartsWith(EVENTNAME; SearchBox.Text))
)

Upvotes: 0

Related Questions