PowerAppsPuzzle: Sorting SelectedItems
Let’s take the scenario where you have a ListBox in a PowerApp that contains sorted information – either alphabetically or numerically, doesn’t matter – similar to the following:
The user selects 1, then 2, then 4, and all is good, however you may notice that sometimes the values are not sorted. You may receive the values out of order like: 4,2,1 or 2,4,1. The reason for this is that the values are in order that they are selected and not necessarily in the order that they exist in the list. For example, if the user selects 1, then 2, then 4, and then deselects 2 and selects 3, the value list will result in 1,4,3.
You can easily demonstrate this using a Label and the Concat() formula to see the results of selecting different items:
[video width="1920" height="1080" mp4="https://msdnshared.blob.core.windows.net/media/2017/10/outofsequence.mp4" loop="true"][/video]
In order to preserve the sequential or sorted order of the values selected, one can use the SortByColumns() formula as the first parameter to the Concat() formula as shown below:
Hope this helps!
Comments
- Anonymous
October 04, 2017
great tip. didn't know about sortbycolumns!