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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Filter gallery based o...
Power Apps
Answered

Filter gallery based on SP list with multi-select choise column

(0) ShareShare
ReportReport
Posted on by 62

Hi everyone!

I hope someone can help me.

I have the following scenario: SharePoint list (MedArticles) with next columns:

Title --> text

Drugs --> choise (can select only one value)

Nosology --> choise (multi-select. Can select from 1 up to 23 values)

Indications --> choise (multi-select. Can select from 1 up to 3 values)

Author_publ --> text

PublicationsYear --> text

The goal is to display articles in the gallery using filters and search.

kalakosha_1-1689943518131.png

I organized the search by Author_publ and filter by drug.
In this case Items property for galArticles looks like this:

 

SortByColumns(
 Filter(
 Filter(
 MedArticlesEng,
 (Drugs.Value = cmbPreparatFilter.Selected.Value || IsBlank(cmbPreparatFilter.Selected.Value))
 ),
 txtSearch.Text in Title || txtSearch.Text in Author_publ
 ),
 "PublicationsYear"
)

 

And this works fine.

Currently, the problem is that I cannot create a filter by Nosology and Indications.

I created glrNosology with Items property 

 

Choices([@MedArticlesEng].Nosology)

 

For chbNosology control object for OnCheck property I set folowing value:

 

Collect(colNosologyFilter,ThisItem)

 

 and for OnUncheck:

 

Remove(colNosologyFilter,ThisItem)

 

When testing the collection, I can see that items are added to the collection when selected and removed from the collection when the item is clicked again.

As example 

kalakosha_2-1689944486338.png

I don't know what value I need to set for the Default property for chbNosology, how to get the value from this collection colNosologyFilter now and how to combine these filters.

I understand that it is possible to create a filter for Indications according to the same principle.

I would appreciate any advice and help.

Categories:
I have the same question (0)
  • Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    @kalakosha - I think the below is what you're trying to do:

     

    On both the OnCheck and UnCheck properties of the Gallery Checkbox for Nosology, enter:

     

    Set(
     varSelectedNosology,
     ShowColumns (
     Filter(
     'Your Nosology Checkbox Gallery'.AllItems,
     Nosology.Value
     ),
     "Value"
     )
    )

     

     

    For the Gallery Checkbox for Indications, use the same logic above:

    Set(
     varSelectedIndications,
     ShowColumns (
     Filter(
     'Your Indications Checkbox Gallery'.AllItems,
     Indications.Value
     ),
     "Value"
     )
    )

     

    In the Items property of the Gallery you're trying to Filter, use:

     

    With(
     {
     _items: SortByColumns(
     Filter(
     MedArticlesEng,
     Len(ccmbPreparatFilter.Selected.Value) = 0 || Drugs.Value = cmbPreparatFilter.Selected.Value,
     Len(txtSearch.Text) = 0 || txtSearch.Text in Title || txtSearch.Text in Author_publ
     ),
     "PublicationsYear"
     )
     },
     With(
     {
     _allfilters: Ungroup(
     ForAll(
     varSelectedNosology As selectedNosology,
     Filter(
     Ungroup(
     ForAll(
     varSelectedIndications As selectedIndications,
     Filter(
     _items,
     selectedIndications.Value in Indications.Value
     )
     ),
     "Value"
     ),
     selectedNosology.Value in Nosology.Value
     )
     ),
     "Value"
     )
     },
     With(
     {
     _Nosologyfilter: Ungroup(
     ForAll(
     varSelectedNosology As selectedNosology,
     Filter(
     _items,
     selectedNosology.Value in Nosology.Value
     )
     ),
     "Value"
     )
     },
     With(
     {
     _Indicationsfilter: Ungroup(
     ForAll(
     varSelectedIndications As selectedIndications,
     Filter(
     _items,
     selectedIndications.Value in Indications.Value
     )
     ),
     "Value"
     )
     },
     If(
     CountRows(varSelectedNosology) > 0 && CountRows(varSelectedIndications) > 0,
     _allfilters,
     If(
     CountRows(varSelectedNosology) > 0 && CountRows(varSelectedIndications) = 0,
     _Nosologyfilter,
     If(
     CountRows(varSelectedNosology) = 0 && CountRows(varSelectedIndications) > 0,
     _Indicationsfilter,
     _items
     )
     )
     )
     )
     )
     )
    )

     

     

    Note the above expression is not delegable and trying to run this beyond the delegable limit will yield undesirable results. 

     

    For more information on many-to-many filters, check this blog post:

     

    https://www.practicalpowerapps.com/data/many-to-many-filters/

     

    ------------------------------------------------------------------------------------------------------------------------------

     

    If I have answered your question, please mark your post as Solved. Remember, you can accept more than one post as a solution.

    If you like my response, please give it a Thumbs Up.

    Imran-Ami Khan

  • Kalakosha Profile Picture
    62 on at

    Hello Amik!

    Thank you for taking the time and opportunity to help me.

    I get an error when I try to set the value for OnCheck and UnCheck properties of the Gallery Checkbox for Nosology and Indications.

    I can't choose a Nosology.Value or Indications.Value. Instead, I can choose ThisItem.Value or ThisRecord or Value.

    I tried these three values in turn without changing at the same time Items property of the Gallery. But did not get the result. Filters do not work.

  • Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    @kalakosha - my fault. I did not make clear that "Nosology" and "Indications" are the names of the Checkbox controls in the Gallery. Replace "Nosology" with whatever the name is for the Checkbox control in the Nosology Gallery and perform the action for the Indications Gallery.

  • Kalakosha Profile Picture
    62 on at

    @Amik - it is not your fault, it is more likely that I do not fully understand what you want to tell me 🙂

    This is my gallery for Nosologys

    kalakosha_0-1690280766189.png

     

    kalakosha_1-1690280802000.png

     

    For chbNosology control for OnCheck and OnUncheck properties I set

    Set(
     varSelectedNosology,
     ShowColumns (
     Filter(
     glrNosology.AllItems,chbNosology.Value 
     ),
     "Value"
     )
    )

    And this is my gallery for Indications:

    kalakosha_2-1690281376391.pngkalakosha_3-1690281393046.png

     

    And for chbIndications control for OnCheck and OnUncheck properties I set

    Set(
     varSelectedIndications,
     ShowColumns (
     Filter(
     glrIndications.AllItems,chbIndications.Value 
     ),
     "Value"
     )
    )

    And now, for Items property my Articles gallery I'm pasting the filter code you gave me at the beginning.

    Here's an example of what a SharePoint list looks like:

    kalakosha_4-1690282037407.png

    And here is an example of what the Articles gallery looks like in the application. Currently, no filters have been applied: not by drugs, not by nosologies, not by indications.
    In other words - all items of the SharePoint list are displayed in the gallery and this is correct.

    kalakosha_5-1690282432822.png

    After these changes that I made, only the filter by drug and the search by author are currently working.

    But the filters for nosologies and indications do not work. I check the nosologies, but the gallery is not filtered.

    As an example, I check only noso_4 checkbo. In this case I should only see 1 item (Article_04). But in the gallery I continue to see all items. 

    I must have messed something up again.

    Thank you once again for finding time for me.

     

  • Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    Hi @kalakosha ,

     

    Could you replace this line:

     

    CountRows(varSelectedNosology) > 0 && CountRows(varSelectedIndications) = 0,

     

     

    With:

     

    CountRows(varSelectedNosology) > 0 && CountRows(varSelectedIndications) = 0 || CountRows(varSelectedNosology) > 0 && IsBlank(varSelectedIndications),

     

     

    And replace this line:

     

    CountRows(varSelectedNosology) = 0 && CountRows(varSelectedIndications) > 0,

     

     

    With:

     

    CountRows(varSelectedNosology) = 0 && CountRows(varSelectedIndications) > 0 || IsBlank(varSelectedNosology) && CountRows(varSelectedIndications) > 0,

     

     

    ------------------------------------------------------------------------------------------------------------------------------

     

    If I have answered your question, please mark your post as Solved. Remember, you can accept more than one post as a solution.

    If you like my response, please give it a Thumbs Up.

    Imran-Ami Khan

  • Kalakosha Profile Picture
    62 on at

    Hi @Amik !

    You are a mage and a wizard! 🙂
    Filters by nosologies and indications really work.
    The only thing is, I'm trying to remove duplicates in the gallery after filtering - it doesn't work yet.
    For example, when I try to filter the list by indication (indic_01 and indic_03),

    kalakosha_1-1690379026438.png

    then according to the SharePoint list

    kalakosha_0-1690378963536.png

     

    , the gallery should display 3 records. And I have one record duplicated (I understand why: it contains both indic_01 and indic_03).

    kalakosha_2-1690379090432.png

    I want to get rid of that.
    The same behavior is observed with nosologies.

    Can you please tell me which way to look?

  • Verified answer
    Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    Hi @kalakosha - please consider the revision below. Note I am not particularly proud of the complexity of this expression, and I cannot speak of its performance, but it should achieve what you need:

     

     

    Filter(//exclude blank rows from appearing in the Gallery for any selected choice which has not yet been entered in the data source
     ForAll(
     Distinct(//exclude duplicates on many-to-many filters
     With(
     {
     _items: SortByColumns(
     Filter(
     MedArticlesEng,
     Len(cmbPreparatFilter.Selected.Value) = 0 || Choice.Value = cmbPreparatFilter.Selected.Value,
     Len(txtSearch.Text) = 0 || txtSearch.Text in Title || txtSearch.Text in Author_publ
     ),
     "Title"
     )
     },
     With(
     {
     _allfilters: Ungroup(
     ForAll(
     varSelectedNosology As selectedNosology,
     Filter(
     Ungroup(
     ForAll(
     varSelectedIndications As selectedIndications,
     Filter(
     _items,
     selectedIndications.Value in Indications.Value
     )
     ),
     "Value"
     ),
     selectedNosology.Value in Nosology.Value
     )
     ),
     "Value"
     )
     },
     With(
     {
     _Nosologyfilter: Ungroup(
     ForAll(
     varSelectedNosology As selectedNosology,
     Filter(
     _items,
     selectedNosology.Value in Nosology.Value
     )
     ),
     "Value"
     )
     },
     With(
     {
     _Indicationsfilter: Ungroup(
     ForAll(
     varSelectedIndications As selectedIndications,
     Filter(
     _items,
     selectedIndications.Value in Indications.Value
     )
     ),
     "Value"
     )
     },
     If(
     CountRows(varSelectedNosology) > 0 && CountRows(varSelectedIndications) > 0,
     _allfilters,
     If(//we use isBlank to accomodate for a blank variable on app start
     CountRows(varSelectedNosology) > 0 && CountRows(varSelectedIndications) = 0 || CountRows(varSelectedNosology) > 0 && IsBlank(varSelectedIndications),
     _Nosologyfilter,
     If(
     CountRows(varSelectedNosology) = 0 && CountRows(varSelectedIndications) > 0 || IsBlank(varSelectedNosology) && CountRows(varSelectedIndications) > 0,
     _Indicationsfilter,
     _items
     )
     )
     )
     )
     )
     )
     ),
     ThisRecord
     ),
     Value
     ),
     Len(ID) > 0
    )

     

     

    ------------------------------------------------------------------------------------------------------------------------------

     

    If I have answered your question, please mark your post as Solved. Remember, you can accept more than one post as a solution.

    If you like my response, please give it a Thumbs Up.

    Imran-Ami Khan

  • Kalakosha Profile Picture
    62 on at

    Hi @Amik ,

    I take my hat off to you.
    It's grand.
    Thanks for the comments on the code.

  • Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    @kalakosha you're welcome. Note I have edited the original solution with a slightly cleaned up expression.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 914

#2
11manish Profile Picture

11manish 627

#3
Valantis Profile Picture

Valantis 598

Last 30 days Overall leaderboard