Power Apps Sort Distinct Filter [With Examples]

Can Power Apps SORT, DISTINCT, and FILTER functions be combined? Yes, it’s possible.

This Power Apps tutorial will explore everything about Power Apps Sort Distinct Filter with various scenarios.

Power Apps Sort Distinct Filter

Suppose you want to sort and filter the distinct values simultaneously in Power Apps. Then, in this case, we will use three Power Apps functions in the same formula: Sort, Distinct, and Filter.

We can combine all these three functions and get the result in a gallery control or a Dropdown control in Power Apps.

Refer to the scenarios below.

Example – 1:

1. I have a SharePoint list named Scheduled Events. This list has various columns with different data types. Such as:

ColumnDatatype
TitleSingle line of text
Department Choice [IT, HR, FINANCE, MARKETING]
LocationChoice [Pentagon, Decagon, Octagon, Nonagon]
Event ManagerPerson
Start Date, End DateDate and time

Also, this list has some records as below:

Power Apps Sort Distinct Filter
Power Apps sort distinct filter

2. In Power Apps, there are two Dropdown controls where one of the dropdowns is used to select the department, and another is to display the location based on the department selection.

3. When the user selects the Department (from the first dropdown), the Location (second dropdown) will filter accordingly based on the department dropdown with distinct and sort values.

4. When I selected the MARKETING department, the location dropdown was filtered with distinct values and sorted accordingly (in ascending order).

Sort distinct filter in Power Apps

5. To achieve this, select the Department dropdown control and apply the below code on its Items property as:

Items = Choices('Scheduled Events'.Department).Value

Department = SharePoint Choice field

6. We can see all the department choice values inside the dropdown menu once we preview the app.

PowerApps Sort distinct filter
PowerApps Sort distinct filter

7. Next, select the Location dropdown and set its Items property as:

Items = Sort(
    Distinct(
        Filter(
            'Scheduled Events',
            Department.Value = ddSelectDepartment.Selected.Value
        ),
        Location.Value
    ),
    Result,
    SortOrder.Ascending
)

Where,

  1. Department = SharePoint Choice field
  2. ddSelectDepartment = This is the first dropdown control name where a user can select the Department value
  3. Location = SharePoint Choice field
  4. Result = This is the second required argument in the formula.
  5. Ascending = Specify the order you want to display in the second dropdown control
Sort distinct filter in PowerApps
Sort distinct filter in PowerApps

8. Save and Preview the app. You can see the result in the location dropdown once you select the department dropdown menu.

This is how to use the Power Apps Sort Distinct Filter function.

Example – 2:

This scenario will discuss working with Power Apps Sort Distinct Filter using a SharePoint Column [Single line of text].

1. There is a SharePoint list named Job Seekers Registration List. This list has some different fields like the following:

ColumnDatatype
First NameBy default, this is a Title field with a single line of text. I just renamed it to First Name.
SurNameSingle line of text
Registration IDNumber
Matric Percentage, 12th Percentage, Graduation SGPA, AddressSingle line of text

This list has some below records as well:

PowerApps sort distinct filters

2. In this scenario, I would like to sort the SharePoint Title field, which should be a unique value in Power Apps. Refer to the image below:

Power Apps sort with distinct

3. To do so, insert a Gallery control and apply the below formula on its Items property as:

Items = Sort(
    Distinct(
        'Job Seekers Registration List',
        Title
    ),
    Result
)

Where,

Title = SharePoint Title Column [Single line of text]

Sort distinct filter Power Apps

4. Finally, select the label that is present inside the gallery and set the below code on its Text property as:

Text = ThisItem.Result
Power Apps Sort distinct filter

5. Save and Preview the app. As shown above, the gallery will appear with the filtered distinct result in ascending order.

This is how to work with the sort distinct filter in Power Apps.

Conclusion

I hope this Power Apps tutorial will be very helpful to know everything about Power Apps Sort Distinct Filter with different examples.

Moreover, you may like some more Power Apps tutorials:

>