Before reading this article, please go through the article links given below.
- Quick Start on Microsoft PowerApps
- Build Asset Checkout App Using Microsoft PowerApps
- How To Build Blank Apps Using Microsoft PowerApps
- How To Add Excel Data Source In Microsoft PowerApps
In PowerApps, we can use the Sort and SortByColumn functions.
Sort Function
The sort function sorts the data in the table. The formula is evaluated for each record of the table and sorts the table. The formula must result in a number, a string, or a Boolean value; it can't result in a table or a record.
Syntax
Sort(Table, Formula [, SortOrder])
Explanation
- Sort Keyword
- Table Table Name
- The formula We apply the formula(If you search more than one column)
- SortOrder Either Ascending(SortOrder.Ascending) /Descending(SortOrder.Descending)
Follow the below steps to work with the Sort function in PowerApps.
Step 1. Log into the PowerApps.
After downloading the PowerApps from the Windows Store, here, we need Microsoft-related organizations (MSDN, Microsoft, Skype, Office 365, etc.,) login ID to log into it.

Step 2. Create a new app in PowerApp.
After login, we will see the Dashboard. There, click on the New button.

Step 3. Choose the Blank App.

Step 4. Designing the app.
Now, let's start designing the app. On the left side, we can see the Individual screens for adding our data, while on the right side, we see the List of Layouts. The formula bar is shown at the top. There, the selected properties are shown. On the right side, we see the "Add Data Source" to add the external data source.

Step 5. Choose the Blank Layout.

Step 6. Insert the Button from the Insert Menu.

Step 7. Add the coding.
Click on the button and add the following code to the OnSelect Event.
Coding
ClearCollect(SivaEnterprise,
{
ProductNo: 100,
ProductName: "Keyboard",
Rate: 500
},
{
ProductNo: 579,
ProductName: "Mouse",
Rate: 600
},
{
ProductNo: 112,
ProductName: "DVD",
Rate: 1500
},
{
ProductNo: 856,
ProductName: "Modem",
Rate: 500
},
{
ProductNo: 469,
ProductName: "Processor",
Rate: 5000
}
)

Step 8. Run the App.

Step 9. Click on the Display button and close the Preview window.

Step 10. Display the data.
Now, go to the File menu and choose Collections.


It will display the content in the table format.
Examples of Sorting functions
Note. To run every example, create a new button paste the example coding to the OnSelecct event, and follow Steps 7 to 10.
Example 1
ClearCollect(SivaEnterprise, Sort(SivaEnterprise, ProductName))
- Explanation It will sort the ProductName by Ascending order (By default it's Ascending order)
- ClearCollect It deletes all the records from a collection and then adds a different set of records to the same collection.
- SivaEnterprise It’s the Collection name
- Sort-Keyword.
- SivaEnterprise Collection name.
- ProductName Column name to sort.
Output

Example 2
ClearCollect(SivaEnterprise, Sort(SivaEnterprise, ProductName, SortOrder.Descending))
- Explanation: It will sort the ProductName by descending order.
- SortOrder.Descending: Sort in Descending order.
Output

SortByColumns Function
The SortByColumns function can also be used to sort a table based on one or more columns. You can combine SortByColumns with a Dropbox for List box control to enable users to select \which column to sort by.
Syntax
SortByColumns(Table, ColumnName1 [, SortOrder1, ColumnName2, SortOrder2, ...])
Explanation
- SortByColumn Keyword
- Table Table Name
- ColumnName1, ColumnName2 more than one column we added
- SortOrder Either Ascending(SortOrder.Ascending) /Descending(SortOrder.Descending)
Examples of SortByCoulumn Function
Example 1
ClearCollect(
SivaEnterprise,
SortByColumns(
SivaEnterprise,
"ProductName",
["DVD", "Mouse"]
)
)
Explanation It will display the DVD and Mouse as first and second data.
Output

Tables are a value in PowerApps, just like a string or number. They can be passed to and returned from functions. Sort and SortByColumn don't modify a table; instead, they take a table as an argument and return a new table that has been sorted.
Conclusion
I hope you understand how to use Sort and SortByColumn in Microsoft PowerApps and how to run it.

Paul HuntPosted Feb 20, 2020, 12:28 PM
I have the records in a Gallery able to show with "#####" of numbers. And it sorts..but doesn't sort how I would like. Can you explain how I can sort the records correctly? In strictly numerical order (i.e. 00001, 00002, 00003, 00004, . . . --> 09999. . . --> 99999)?
Adam AhmadPosted Jan 2, 2020, 12:32 AM
Thank you mam.. but I have one problem. Can you teach me how to sorting the data by date. For example I have a lot of data, and all the data have different date. So my apps can sorting all the data by date.
Prasanna MuraliPosted Oct 22, 2016, 11:42 AM
Nice post mam
Joe WilsonPosted Oct 21, 2016, 2:43 PM
Thank you.
Madhanmohan DevarajanPosted Oct 21, 2016, 2:16 PM
Kudos! you have started coding in PowerApps? That's great.