No More Duplicates: Power Apps Distinct in Action

The Distinct function in Power Apps is used to remove duplicate results from a data source.

This is particularly useful when you want to display unique values in controls such as dropdowns, galleries, or radio buttons.

Creating a Collection

Suppose you create a collection called Products in the OnStart property of your app. Each record contains a Product, Department, and Store.

ClearCollect(Products,
{Product:"Laptop", Department:"Electronics", Store:"Tech Heaven"},
{Product:"Chair", Department:"Furniture", Store:"Home Comfort"},
{Product:"Table", Department:"Furniture", Store:"Home Comfort"},
{Product:"Phone", Department:"Electronics", Store:"Tech Heaven"} )

Using Distinct in a Dropdown

If you bind a dropdown to the Products collection and set its Items property to Products.Department, you may see duplicate values like Electronics appearing multiple times.

To remove duplicates, use the Distinct function:

Distinct(Products, Department)

This will display each department only once, e.g., Electronics and Furniture.

Applying Distinct to Other Columns

You can apply Distinct to any column, such as Store, to show each store only once. Additionally, you can wrap Distinct with Sort to order results alphabetically:

Sort(Distinct(Products, Store), Result)

Distinct with Galleries and Radio Controls

Since Distinct returns a single-column table, it can be used with any control that accepts a table as a data source:

  • Vertical Gallery: Distinct(Products, Store)
  • Radio Control: Distinct(Products, Department)

Combining Distinct with AddColumns

You can create new columns using AddColumns and then apply Distinct to them. For example, combining Store and Department into a new column:

Distinct(
AddColumns(Products, "StoreDepartment", Store & " " & Department),
StoreDepartment )

This ensures that duplicate combinations like Tech Heaven Electronics appear only once.

Using Distinct with External Data Sources

The Distinct function is not limited to collections. It can also be applied to external data sources such as SharePoint lists or Dataverse tables.

For example, if you have a Books table in Dataverse with multiple records by the same author, you can display each author only once:

Distinct(Books, Author)

Key Takeaways

  • Distinct removes duplicate values from a column.
  • It returns a single-column table named Result.
  • Can be combined with Sort and AddColumns for more complex scenarios.
  • Works with collections and external data sources like SharePoint or Dataverse.
  • Useful in dropdowns, galleries, radio buttons, and other controls that accept tables.

Conclusion

The Distinct function in Power Apps is a powerful tool for cleaning up duplicate values and ensuring that your app displays unique, meaningful data to users.

Whether working with collections or external tables, Distinct helps streamline your app’s data presentation.

Comments

Leave a Comment

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