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
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
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)
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
The presentation of the data can be refined further
To sort in descending order, add the additional attribute
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!