web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Nesting Filter inside ...
Power Apps
Unanswered

Nesting Filter inside Search doesn't work

(0) ShareShare
ReportReport
Posted on by

Hi,

 

i have an app which is based on CDS. in the app i have a screen which has a gallery where its items can have multiple filters.

in order to apply nested filters, i have tried nesting Filter inside Search, Search inside Filter, and Filter inside Filter, but whenever both filter values are used, one of the functions loses the original filtered subset.

 

I have also tried using && and || but nothing has worked so far!

 

any suggestions?

I have the same question (0)
  • Khawaja Profile Picture
    7 on at

    Hi @Anonymous,

    i have the same problem... check my post here:

     

    https://powerusers.microsoft.com/t5/General-Discussion/Search-Filter-nested-functions-with-wrong-behaviour/td-p/99750

     

    regards,

    Mohammad

  • Community Power Platform Member Profile Picture
    on at

    Hi @Anonymous

     

    Please share the formula you are using to filter the data. Having multiple filters for data source is doable.

     

    Here is an example of simple multiple filter

     

    Filter(
     MyDataSource,
     Name = Dropdown1.Selected.Value,
     City = Dropdown2.Selected.Value,
     Country = Dropdown3.Selected.Value
    )

    If you give us more details on your specific needs we can show you more tailored answer.

  • mokhawaja Profile Picture
    239 on at

    thanks @Anonymous for your suggestion... but we are talking about nesting Search inside Filter or vice versa:

     

    Filter(Search(Doctors, TextInput6.Text,"DoctorName"), City=ComboBox2.Selected.Value)
  • Community Power Platform Member Profile Picture
    on at

    Hi @mokhawaja

     

    In your case if you are using a combo box there is no Selected.Value.

     

    The correct syntax with ComboBox:

     

    Filter(Search(Doctors, TextInput6.Text,"DoctorName"), City in ComboBox2.SelectedItems)

     

     I checked with my datasource (SQL Server) and this Filter + Search is working as expected.

  • Community Power Platform Member Profile Picture
    on at

    Hi @mokhawaja

     

    Actually, for it to work properly there needs to be adjustment. Because if you use the function I wrote above it will not work when ComboBox is empty, and sometimes when Search Input box is empty.

     

    To overcome this you need to write IF() statements and it would be something like this:

    If(
     IsEmpty(ComboBox2.SelectedItems) && IsBlank(TextInput6.Text),
     Doctors,
     IsEmpty(ComboBox2.SelectedItems) && !IsBlank(TextInput6.Text),
     Search(Doctors, TextInput6.Text,"DoctorName"),
     !IsEmpty(ComboBox2.SelectedItems) && IsBlank(TextInput6.Text),
     Filter(Doctors,City in ComboBox2.SelectedItems),
     Filter(Search(Doctors, TextInput6.Text,"DoctorName"), City in ComboBox2.SelectedItems)
    )

    However even this is not that good since the IN operator can not be delegated (means that you will be seeing only partial data if you have more than 500 rows). To solve this you can use Dropdown for cities instead of combo box (you will be able to search one city at a time instead of selecting multiple).

     

  • mokhawaja Profile Picture
    239 on at

    Thanks again @Anonymous, actually i used something similar to your suggestion and this is my full formula 

    SortByColumns(If(IsBlank(SpecialtyComboBox.Selected) && IsBlank(CityComboBox.Selected),
    Search(Doctors, TextInput3.Text, "DoctorName","Area"), 
    If(!IsBlank(SpecialtyComboBox.Selected) && IsBlank(CityComboBox.Selected), Filter(Search(Doctors, TextInput3.Text, "DoctorName","Area"), Specialty = SpecialtyComboBox.Selected.Value), 
    If(!IsBlank(CityComboBox.Selected) && IsBlank(SpecialtyComboBox.Selected), Filter(Search(Doctors, TextInput3.Text, "DoctorName","Area"), City = CityComboBox.Selected.Value), If(!IsBlank(SpecialtyComboBox.Selected) && !IsBlank(CityComboBox.Selected),Filter(Search(Doctors, TextInput3.Text, "DoctorName","Area"), Specialty = SpecialtyComboBox.Selected.Value && City = CityComboBox.Selected.Value))))), "DoctorName", Ascending)

    notice that i opted for the single selection in the comboboxes to use the selected.value, and to be a delegable function.

     

    and as you can see in my screenshot i have two comboboxes to filter on and a search textbox, so whenever the comboboxes are selected with no search the filte works fine!

    but when i use the search box then its results will override the filters and bring back everything.

  • Verified answer
    Community Power Platform Member Profile Picture
    on at

    I managed to find a solution for this problem, in which i used Collections.

     

    So for the first level of filteration:

    ClearCollect(nameofCollectionvar,Filter(tablename,field1=value1 && field2= value2));

     

    you will then use the same collection you generated above for the below search

    Search(nameofCollectionvar,textfield.txt,"field3","field4"))

  • mokhawaja Profile Picture
    239 on at

    Hi @Anonymous,

    yes it is confirmed that my same formula works as expected on a collection, and this proves that this is a bug in the search function or filter when working on live data

    Filter(Search(CacheDoctors, TextInput3.Text, "DoctorName","Area"), 
    Specialty = SpecialtyComboBox.Selected.Value && 
    City = CityComboBox.Selected.Value))))), "DoctorName", Ascending)

    CacheDoctors is a collection of the Doctors entity.

     

    i hope someone from Microsoft pays some attention to this

    @v-micsh-msft@v-monli-msft

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard