So you add a gallery to your app in Power Apps and you want to create some filters (distinct filters of course!).
Galleries
Table of Contents
I’ve said it before, Galleries are everywhere in Power Apps. Whenever you need to show a list of records, galleries are your friend (and enemies sometimes). The Gallery control can be configured in many ways to display records next to each other, underneath each other or both.
The simplest form of using galleries is listing data that comes from for example SharePoint lists or Dataverse tables.
Below I’ve got an example of a gallery that shows data from a SharePoint list that contains information about all connectors in the Power platform.

Building distinct filters on a gallery
I now want to build a dropdown that will filter my data on the Release column. This column has the internal name of Release Tag.
First of all I am going to add a dropdown control in my Power App. This dropdown will appear just above the header of the column.
Then it is important that every value of the Release column in my Connectors list will only appear once in my dropdown.
The most obvious way is to set the items in my dropdown to the following code, using the distinct filters to filter the gallery. Using the distinct function you will make sure that you only get the unique values.
distinct(Connectors.'Release Tag', 'Release Tag').Result
However this doesn’t work. The dropdown will remain empty as we can see in the screenshot below.

Note that when you set a collection to hold the data, you may get a better working filter.
So in my case I’m going to set a collection called colFilter using the following line of code in my app start-up. In this case we only need to construct the list of available options once, hence the app OnStart is a good place to create this collection.
Collect(colFilter, Distinct(Connectors.'Release Tag','Release Tag').Result)
You could also do this within the screen’s OnVisible configuration or maybe in a timer if you want your dropdowns to update on a regular basis. Or maybe even in an OnChange even if your data is flexible. It all depends on the details what is the best option for you.

And now the available options are displayed as expected in our dropdown. We could of course also sort the items in the drop down using the Sort function, but that is a post for another day.
In some situations you might want to filter out the blank values as well. But in our case we might want to select the records that have an blank value for a specific property. The same way a <All> option may be useful if we want to be able to select all values and disable the filter.

And now as we select a value from our dropdown the right records appear in our gallery. In the expression we simply filter by the selected value in the dropdown using the Filter function. This is making the filtering process on galleries easy.
You could also consider using named formulas in this case. That way all you data filtering operations are configured within the Formulas property of the app. Especially if the same filters are used in multiple places then Named Formulas can be the better option.

FAQs
How do you get unique values in a dropdown in Power Apps?
The Distinct function can help creating unique values in a dropdown.
Can the distinct function be used in other controls than a dropdown?
Yes, the distinct function could also be useful within Galleries or Combobox controls.
Discover more from SharePains
Subscribe to get the latest posts sent to your email.