Distinct filters in Power Apps

Create Distinct filters for Power Apps galleries

So you add a gallery to your app in Power Apps and you want to create some filters (distinct filters of course!). This is the post to read!

Galleries

I’ve said it before, Galleries are everywhere in Power Apps.

The simplest form of using galleries is listing data that comes from lists or 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.

Create Distinct filters for Power Apps galleries 1

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’m going to add a dropdown control in my Power App. This dropdown will appear just above the header of the 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.

Create Distinct filters for Power Apps galleries 2

Note that when you set a collection to hold the result that you will get a better working filter.

So in my case I’m going to set a collection called colFilter using the follownig line of code in my app startup.

Collect(colFilter, Distinct(Connectors.'Release Tag','Release Tag').Result)

You could also do this within the screens’ OnVisible configuration or maybe in a timer if you want your dropdowns to update on a regular basis.

Create Distinct filters for Power Apps galleries 3

And now the possible options are displayed as expected.

Distinct filters in Power Apps

And now as we select a value from our dropdown the right records appear in our gallery.

Create Distinct filters for Power Apps galleries 4

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: