By default, in Power Apps, the data in a choice column is displayed in the order in which the choice options are entered in Dataverse

However, choice columns can be filtered and sorted when displayed in a Canvas app. How to do the sorting isn’t immediately obvious, so In this post I will demo how this can be done

Premier League banner

Sort a Dataverse Choice Column

Because the season finished yesterday, I’ve created a Dataverse choice set called Team that have been entered corresponding to the final position of each football club in the 2022/23 English Premier League, shown opposite

I’ve also created a Dataverse table called PremierLeague and added a choice column to the table called Team which contains the choice list

I could sort the choice data set in alphabetical order in Dataverse – see the option to sort towards the top right of the image, but lets not do this in Dataverse, lets sort the teams alphabetically in a Canvas power app instead

Premier League final placings in a Dataverse choice set

In Power Apps Studio, connect to the PremierLeague Dataverse table and create a dropdown box

To display the teams in their final positions, in the Items property of the dropdown box, just add the following code:

Choices(Team)
unsorted league table

The teams are displayed in the dropdown box exactly as they are in Dataverse, starting with Manchester City as shown in the insert

To display alphabetically, we use Text(Value). This isn’t immediately offered  as an option by intellisense so has to be typed. Update the formula to the following:

Sort(Choices(Team),Text(Value))

Now the choices  are displayed alphabetically

sorted Premier League table

The presentation of the data can be refined further

To sort in descending order, add the additional attribute

Sort(Choices(Team),Text(Value),SortOrder.Descending)

The choice set can also be filtered, for example to only contain the teams that start with the letter L:

Filter(
Choices(Team),
StartsWith(
Text(Value),
"L"
)
)

To both filter and display alphabetically, wrap the filter in a Sort function:

Sort(
Filter(
Choices(Team),
StartsWith(
Text(Value),
"L"
)
),
Text(Value)
)

Because my team was relegated yesterday, the alphabetical order looks much more pleasing to my eye than the final positions. Here’s hoping Leeds United have a speedy return to the Premier League!

Leave a Comment

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

Scroll to Top