Latest Posts

PowerApps Extract unique values from table or collection


The Distinct function in Power Apps is used to extract unique values from a column of a table or collection. This function is particularly useful for removing duplicates and obtaining a list of unique values, such as when creating dropdown menus or filtering data.

PowerApps – Distinct() function Syntax

Distinct(Table, Column)

  • Table: The table or collection from which you want to extract unique values.
  • Column: The column for which you want to find distinct values.

Notes:

  1. Column Name: Ensure that the column name passed to the Distinct function is correct and exists in the table or collection.
  2. Combining with Other Functions: Combine Distinct with other functions like Filter, Sort, CountRows, and Concat to perform complex data manipulations and analyses.
  3. Performance: Be mindful of the performance when using Distinct with large datasets. Consider using delegation where possible to handle large data sources efficiently.

PowerApps – Extract Unique Values from a Collection

Suppose you have a collection named Products and you want to extract a list of unique product names.

  1. Create the Collection:

ClearCollect(Products,

    Table(

        {ProductID: 1, ProductName: "Laptop", Price: 1000},

        {ProductID: 2, ProductName: "Tablet", Price: 500},

        {ProductID: 3, ProductName: "Laptop", Price: 1200},

        {ProductID: 4, ProductName: "Monitor", Price: 300}

    )

);

  1. Extract Unique Product Names:
    • Add a Label control.
    • Set the Text property of the Label to:

Concat(Distinct(Products, ProductName), Result & ", ")

This will display the unique product names: "Laptop, Tablet, Monitor".

PowerApps – Get Unique (Distinct) values in a Dropdown Menu

Suppose you want to populate a dropdown menu with unique product categories from a collection.

  1. Create the Collection:

ClearCollect(Products,

    Table(

        {ProductID: 1, ProductCategory: "Electronics"},

        {ProductID: 2, ProductCategory: "Furniture"},

        {ProductID: 3, ProductCategory: "Electronics"},

        {ProductID: 4, ProductCategory: "Appliances"}

    )

);

  1. Populate the Dropdown Menu:
    • Add a Dropdown control.
    • Set the Items property of the Dropdown to:

Distinct(Products, ProductCategory)

This will populate the dropdown with unique product categories: "Electronics", "Furniture", "Appliances".

PowerApps – Count Unique (Distinct) Values

Suppose you want to count the number of distinct product categories in a collection.

  1. Create the Collection:

 

 

ClearCollect(Products,

    Table(

        {ProductID: 1, ProductCategory: "Electronics"},

        {ProductID: 2, ProductCategory: "Furniture"},

        {ProductID: 3, ProductCategory: "Electronics"},

        {ProductID: 4, ProductCategory: "Appliances"}

    )

);

  1. Count the Distinct Product Categories:
    • Add a Label control.
    • Set the Text property of the Label to:

CountRows(Distinct(Products, ProductCategory))

This will display the number of unique product categories, which is 3.


We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint