Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Can't merge 2 different code into one to filter a gallery

(0) ShareShare
ReportReport
Posted on by

Hi guys!

I'm reaching out to get some help with merging 2 different parts of code I have written. They work independently but I can't figure out a way to take the first code and merge it with the second.

Any help is very much appreciated!

 

1. First code, filtering the gallery with a combobox that displays Office 365 users

If(
 IsEmpty(ComboBox2_5.SelectedItems);
 lst_suivi_materiel;
 Filter(
 lst_suivi_materiel;
 'Agent Propriétaire'.DisplayName in ComboBox2_5.SelectedItems.DisplayName)
)

 

2. Second code, that shows all the other filters for the gallery

Sort(//On trie par date dans l'ordre ascendant les résultats
 Search(//on permet de rechercher grâce à "Search_IMEI.Text" le texte entré dans la liste
 Filter(//ici on filtre la liste en affichant toujours au minimum tous les éléments, puis on trie par UO, type de matériel et agent
 lst_suivi_materiel;
 (IsBlank(Combo_UO_4.Selected.Value) || StartsWith(
 UO;
 Combo_UO_4.Selected.Value
 )) && (IsBlank(Cat_Combo_2.Selected.Value) || StartsWith(
 Type_de_materiel;
 Cat_Combo_2.Selected.Value
 )) && (IsBlank(Cat_Combo_3.Selected.Value) || StartsWith(
 Disponibilité;
 Cat_Combo_3.Selected.Value
 ))
 );
 Search_IMEI_1.Text;
 "Title" 
 );
 'Date de dotation';
 SortOrder.Ascending
)

 

Thanks!

Categories:
  • Verified answer
    Community Power Platform Member Profile Picture
    on at
    Re: Can't merge 2 different code into one to filter a gallery

    Hi again! Thanks for you answer, this solution wasn't working but I have figured out a way to make it work this is my final code for anyone encountering the same issue :

    Sort(
     Search(
     Filter(
     Datasource;
     (IsBlank(ComboBox.Selected.Value) || StartsWith(
     Column;
     ComboBox.Selected.Value
     )) && (IsBlank(ComboBox2.Selected.Value) || StartsWith(
     Column;
     ComboBox2.Selected.Value
     )) && (IsBlank(ComboBox3.Selected.Value) || StartsWith(
     Column;
     ComboBox3.Selected.Value
     )) && (IsBlank(ComboBox4.SelectedItems.DisplayName) || 
     ColumnUser.DisplayName in ComboBox4.SelectedItems.DisplayName
     )
     );
     SearchInput.Text;
     "Title" 
     );
     Column;
     SortOrder.Ascending
    )
  • WarrenBelz Profile Picture
    148,060 Most Valuable Professional on at
    Re: Can't merge 2 different code into one to filter a gallery

    @Anonymous ,

    That is correct - the in filter is not Delegable, however the code I provided was simply copying the two elements of what you posted - if they worked for you, then the combined code should. If you want to improve the Delegation quality, you can do this

    With(
     {
     wData:
     Sort(
     Filter(
     lst_suivi_materiel;
     (
     Len(Combo_UO_4.Selected.Value) = 0 || 
     StartsWith(
     UO;
     Combo_UO_4.Selected.Value
     )
     ) && 
     (
     Len(Cat_Combo_2.Selected.Value) = 0 || 
     StartsWith(
     Type_de_materiel;
     Cat_Combo_2.Selected.Value
     )
     ) && 
     (
     Len(IsBlank(Cat_Combo_3.Selected.Value) = 0 || 
     StartsWith(
     Disponibilité;
     Cat_Combo_3.Selected.Value
     )
     )
     );
     'Date de dotation'
     )
     };
     Search(
     Filter(
     wData;
     IsEmpty(ComboBox2_5.SelectedItems) ||
     Agent Propriétaire'.DisplayName in ComboBox2_5.SelectedItems.DisplayName
     );
     Search_IMEI_1.Text;
     "Title" 
     )
    )

    but you need to be aware that the record numbers out of the top With() statement need to be under your Delegation limit. 

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • Community Power Platform Member Profile Picture
    on at
    Re: Can't merge 2 different code into one to filter a gallery

    Thank you for your answer!
    I was using StartsWith because I am only using a ComboBox for the user research every other "Cat_Combo" is actually a dropdown.

     

    Pasting your formula into the Items parameter of the Gallery I have "&&" ; "||" and "in" underlined in blue saying they don't work well on large databases. And also, when nothing is selected it still displays an empty gallery.

    so_fortyfour_0-1681887208862.png

     

  • WarrenBelz Profile Picture
    148,060 Most Valuable Professional on at
    Re: Can't merge 2 different code into one to filter a gallery

    Hi @Anonymous ,

    Try this - I am also wondering why you are using StartsWith on the Combo Boxes when it would usually be an exact match.

    Sort(
     Search(
     Filter(
     lst_suivi_materiel;
     (
     IsBlank(Combo_UO_4.Selected.Value) || 
     StartsWith(
     UO;
     Combo_UO_4.Selected.Value
     )
     ) && 
     (
     IsBlank(Cat_Combo_2.Selected.Value) || 
     StartsWith(
     Type_de_materiel;
     Cat_Combo_2.Selected.Value
     )
     ) && 
     (
     IsBlank(Cat_Combo_3.Selected.Value) || 
     StartsWith(
     Disponibilité;
     Cat_Combo_3.Selected.Value
     )
     ) &&
     (
     IsEmpty(ComboBox2_5.SelectedItems) ||
     Agent Propriétaire'.DisplayName in ComboBox2_5.SelectedItems.DisplayName
     )
     );
     Search_IMEI_1.Text;
     "Title" 
     );
     'Date de dotation';
     SortOrder.Ascending
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 770 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 494

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 399