Get Distinct List of items

PowerApps distinct collections

When you have large arrays or collections of data and and the data has duplicates, you migth want to use the PowerApps distinct function

Power Apps distinct function

There is a Distinct function which returns a unique list of values however that only works on a single field. So that is great for filling drop downs but not very good when you want to fill a gallery with data.

In this post I will describe an easy way to solve this problem.

I started by creating  a collection that looks like this:

[
{Title:"Item1", Description: "Description 1"},
{Title:"Item1", Description: "Description 1"},
{Title:"Item2", Description: "Description 2"},
{Title:"Item3", Description: "Description 3"},
{Title:"Item3", Description: "Description 3"}
]
Within a Gallery this could look like this:
Large list of items in a Gallery

As you can see I’ve got 5 items and 2 of them are duplicates

To get my gallery to display the items I’m setting the OnStart of my app to:

[{Title:"Item1", Description: "Description 1"},
{Title:"Item1", Description: "Description 1"},
{Title:"Item2", Description: "Description 2"},
{Title:"Item3", Description: "Description 3"},
{Title:"Item3", Description: "Description 3"}
]
Now I can use the distinct function to create myself an index unique items
ClearCollect(MyIndex, Distinct(MyItems, Title));

Using the MyIndex I can now create a gallery of list itemsIndex the items

However this still doesn’t give me all the columns.

Now setting the label value to:

First(Filter(MyItems,Title = ThisItem.Result)).Description
PowerApps Distinct List of items

Other related articles

Unique items with Distinct function

2 thoughts on “PowerApps distinct collections

Leave a Reply

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

%d bloggers like this: