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 / Use variable to filter...
Power Apps
Answered

Use variable to filter a gallery

(0) ShareShare
ReportReport
Posted on by 23

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?

Categories:
I have the same question (0)
  • Verified answer
    v-liwei-msft Profile Picture
    Microsoft Employee on at

    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

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
11manish Profile Picture

11manish 530

#2
WarrenBelz Profile Picture

WarrenBelz 459 Most Valuable Professional

#3
Haque Profile Picture

Haque 314

Last 30 days Overall leaderboard