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.
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.
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.
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.
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.
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 fucntion only takes Tables and not arrays or collections.
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.