Table with unique items using the distinct function

The basic Distinct function usage

In this post I’m looking at creating unique values within a gallery in PowerApps. I started by creating a Gallery with a list of items by feeding the gallery with some json containing some titles set to numbers.

Gallery with items

The labels control that I’m using is set to thisItem.Value.Title and this displays each number related to each item in my array of items.

Label

Now I’m going to take that same array of items but I want to only display unique items. In short on of the two “4” items should disappear.

This can be done with the Distinct functions however it will be needed to convert the array into a Table first. This can be done with the Table function.

Note that in the above there isn’t an array in my Table but a number of records passed into the Table.

Gallery with records

Also note that the labels in this gallery need to be set to ThisItem.Result for them to appear properly in the overview presented by my second gallery.

Distict labels

 

Moving towards Tables

Very soon we will see why feeding the gallery with an array of items may not be the best idea. To make the above two examples more similar I’m going to feed both Galleries with Tables. My first Gallery will now have items that look like this look like this.

Items with table

Now I can use the items in Gallery 1 as a source for Gallery 2, once again with the Distinct function, but as the Items in Gallery 1 are using a Table it is now a piece of cake to get unique values back! Note that the Distinct function only takes Tables and not arrays or collections.

Distinct table

So in short, if you have a choice of feeding a Gallery with a collection or a table, then you might want to choose a table instead. It makes it a lot easier to use function like distinct.

 

By Pieter Veenstra

Business Applications and Office Apps & Services Microsoft MVP working as a Microsoft Productivity Principal Consultant at HybrIT Services. You can contact me using contact@veenstra.me.uk.

2 thoughts on “PowerApps – Get your unique items listed in a gallery”

Leave a Reply

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