Distinct function in PowerApps

Summarizes records of a table, removing duplicates.

Description

The Distinct function evaluates a formula across each record of a table and returns a one-column table of the results with duplicate values removed. The name of the column is Result.

Fields of the record currently being processed are available within the formula. You simply reference them by name as you would any other value. You can also reference control properties and other values from throughout your app. For more details, see the examples below and working with record scope.

When used with a data source, this function can't be delegated. Only the first portion of the data source will be retrieved and then the function applied. The result may not represent the complete story. A warning will appear at authoring time to remind you of this limitation and to suggest switching to delegable alternatives where possible. For more information, see the delegation overview.

Syntax

Distinct( Table, Formula )

  • Table - Required. Table to evaluate across.
  • Formula - Required. Formula to evaluate for each record.

Example

  1. Insert a Button control, and set its OnSelect property to this formula.

    ClearCollect( CityPopulations,
        { City: "London",    Country: "United Kingdom", Population: 8615000 },
        { City: "Berlin",    Country: "Germany",        Population: 3562000 },
        { City: "Madrid",    Country: "Spain",          Population: 3165000 },
        { City: "Hamburg",   Country: "Germany",        Population: 1760000 },
        { City: "Barcelona", Country: "Spain",          Population: 1602000 },
        { City: "Munich",    Country: "Germany",        Population: 1494000 }
    );
    
  2. Select the button while holding down the Alt key.

    The formula is evaluatd and the CityPopulations collection is created which you can show by selecting CityPopulations in the formula bar:

    CityPopulations collection shown in result view

  3. Insert a Data table control, and set its Items property to this formula:

    Distinct( CityPopulations, Country )
    

    You can view the result of this formula in the formula bar by selecting the entire formula:

    Output from Distinct function shown in result view

  4. Use the Edit fields link in the data table's properties pane to add the Result column:

    Output from Distinct function shown in data table

  5. Insert a Label control, and set its Text property to the formula:

    First( Sort( Distinct( CityPopulations, Country ), Result ) ).Result
    

    This formula sorts the results from Distinct with the Sort function, takes the first record from the resulting table with the First function, and extracts the Result field to obtain just the country name.

    Output from Distinct function showing the first country by name