Overview
Adding sorting functionality to a gallery is a great to for users to arrange their data. It’s easy to set up and involves a couple variables and an icon for each column that requires sorting.
YouTube
Add Sort Icons
The first step in sort columns in a gallery is to add the Sort icon beside the columns headers

Once added, there are a couple of variables that need to be set when the OnSelect property is triggered. sortColumn determine which column should be currently sorted and sortDirection defines what the direction should be (Ascending or Descending)
Set(sortDirection,
If(sortDirection = Descending,
Ascending,
Descending
)
);
Set(sortColumn,
“sortName”
);

Repeat this step for additional columns requiring sort functionality
Update Gallery Items Property
On the Items property of the gallery, AddColumns function is required to add the sortName and sortCity columns that will be sorted. Each of these columns added will reference their corresponding fields. The Items property should initially look like this:
AddColumns(accountList, “sortName”, ‘Account Name’, “sortCity”, ‘Address 1: City’)
Once the columns have been added to your data, you can now add the SortByColumns function to sort. This defines which column should be sorted and in which direction
SortByColumns({previous command}, sortColumn, sortDirection)
The final statement should look like the following:
SortByColumns(AddColumns(accountList, “sortName”, ‘Account Name’, “sortCity”, ‘Address 1: City’), sortColumn, sortDirection)

At this point, you will be able to sort column in either direction.
