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

Use variable to filter a gallery

I have a gallery where I want to filter based on a variable.

 

CollectionA table looks like this.

IDNameCreated By
3TestATestB
31TestABTestBA

 

I have created a dropdown to filter the gallery based on ID.

 

ClearCollect(colCampID,AddColumns(ShowColumns(DataSource, "ID"),"IDText", Text(ID)), {IDText: "Any"});

ClearCollect(colName,AddColumns(ShowColumns(DataSource, "Person"),"Name", Person), {Name: "Any"});

ClearCollect(colCreatedBy,AddColumns(ShowColumns(CampaignCentral, "Author"),"CreatedBy", Author.DisplayName), {CreatedBy: "Any"});

colCampID looks like this now:

 

IDText
3
31
Any

 

I am using colCampID.IDText as a dropdown values to filter.

Dhruv100322_0-1651636540868.png

 

I have several similar filters on Name and Created By as well and using collection colName and  colCreatedBy for items for dropdown.

 

Dhruv100322_0-1651637291968.png

 

 

I have created a local variable on change of all the dropdown.

 

On Change of ID Dropdown: 

 

 

UpdateContext({varFilterID: If(Self.Selected.IDText = "Any", Blank()& "in Text('ID')", "Dropdown1.Selected.IDText = Text('ID')") })

 

 

 

On Change of Name Dropdown: 

 

 

UpdateContext({varFilterName: If(Self.Selected.Value = "Any", Blank()& "in Name", "Dropdown1_1.Selected.Value= Name") })

 

 

 

On Change of Created By Dropdown: 

 

 

UpdateContext({varFilterCreatedBy: If(Self.Selected.Value = "Any", Blank()& "in 'Created By'", "Dropdown1_2.Selected.Value= 'Created By'") })

 

 

 

All three conditions needs to be applied.

 

So basically if "Any" is selected in a dropdown then get all records else get that specific record.

 

Currently my Gallery Items is as follows: 

 

 

Filter(CollectionA , varFilterID,varFilterName, varFilterCreatedBy)

 

 

 

This is not working for me. Can you please help?

1 ACCEPTED SOLUTION

Accepted Solutions
v-liwei-msft
Microsoft
Microsoft

Hi @Dhruv100322 ,

 

When creating a variable, you cannot define it as a formula that does not return any value.

I suggest you use this formula when filtering gallery:

 

Filter(

    CollectionA,
    ("Any"=Dropdown1.Selected.IDText || Text(ID)=Dropdown1.Selected.IDText) &&
    ("Any"=Dropdown1_1.Selected.Name || Name=Dropdown1_1.Selected.NameText) &&
    ("Any"=Dropdown1_2.Selected.CreatedByText || 'Created By'=Dropdown1_2.Selected.CreatedByText)
)

 

Beat Regards,

Levi

View solution in original post

1 REPLY 1
v-liwei-msft
Microsoft
Microsoft

Hi @Dhruv100322 ,

 

When creating a variable, you cannot define it as a formula that does not return any value.

I suggest you use this formula when filtering gallery:

 

Filter(

    CollectionA,
    ("Any"=Dropdown1.Selected.IDText || Text(ID)=Dropdown1.Selected.IDText) &&
    ("Any"=Dropdown1_1.Selected.Name || Name=Dropdown1_1.Selected.NameText) &&
    ("Any"=Dropdown1_2.Selected.CreatedByText || 'Created By'=Dropdown1_2.Selected.CreatedByText)
)

 

Beat Regards,

Levi

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Top Solution Authors
Users online (3,573)