How To Use The PowerApps Distinct Function

PowerApps Distinct Function 1

The PowerApps Distinct function helps to remove duplicate values from a given dataset or column and returns only the unique values. This can be useful when you want to present a list of unique items to users or when you need to perform calculations or analysis based on distinct values.

PowerApps Distinct Function

Syntax

Distinct( Table, Formula )

Input parameters

  • Table (mandatory): The table that potentially contains duplicate entries for a property.
  • Formula (mandatory): The property formula that addresses the property that potentially contains duplicate entries.

Return value

  • A set of the property described addresses in the input parameters that contains only unique values – every entry only exists once.

PowerApps Distinct Examples

To understand the distinct function in PowerApps, we take a look at some examples.

Simple PowerApps Distinct Collection Example

Let’s start with a very simple example.

ClearCollect(numbers,1,2,2,3,1,3,4);

// numbers = [1,2,2,3,1,3,4]

ClearCollect(uniqueNumbers,Distinct(numbers,Value));

// uniqueNumbers = [1,2,3,4]

Duplicate entries are removed and every entry is unique.

PowerApps Distinct Sort And Filter Example

Let’s take a look at a more complex example that is more realistic.

Imagine we have a product catalog like this:

ProductCategoryPrice
Apple Print ShirtShirts$19,99
Slim Fit JeansJeans$50,00
Straight JeansJeans$76,50
White SneakerShoes$49,29

The data of the product catalog might come from a SharePoint list or database. To keep it simple, we define the data simply by ourselves.

ClearCollect(
    products,
    { Product: "Apple Print Shirt", Category: "Shirts", Price: "$19,99"},
    { Product: "Slim Fit Jeans", Category: "Jeans", Price: "$50,00"},
    { Product: "Straight Jeans", Category: "Jeans", Price: "$76,50"},
    { Product: "White Sneaker", Category: "Shoes", Price: "$49,29"}
);

Let’s create a simple gallery!

powerapps distinct gallery

Now we want to filter products by category by clicking on a category in a sidebar like this:

powerapps distinct filter

The Items property of the gallery for the sidebar uses the Distinct function. We also use a Distinct Sort function combination.

Sort(Distinct(products,Category),Value)

The Items property of the gallery for the products simply looks like this:

Filter(products,Category = CategoriesGallery.Selected.Value)

As you can see, the Distinct function can be very useful!

Nevertheless, keep in mind that the Distinct function is primarily used for working with datasets that are not necessarily already unique. If you are dealing with a dataset that inherently contains only unique values (e.g., primary keys in a database), using Distinct may not be necessary.

Leave a Comment

Your email address will not be published. Required fields are marked *