@AmyF
To understand this first, we need to look into the SortByColumn():
Syntax :
SortByColumns( Table, ColumnName1 [, SortOrder1, ColumnName2, SortOrder2, ... ] )
The basic use of this following mdevaney example will be
SortByColumns( Engeener cost List, IncidentCity, SortOrder.Ascending)
This will pull records from this List / Table and Sort them A-Z if we pick Descending, we will get results Z-A
or You can call it from Small to large or large to Small.
To create more dynamic behaviour of this syntax in the example rather than placing Fixed SortOrder.Ascending or SortOrder.Descending there is an IF statement.
IF Statment works based on an assigned rule, in this case, AscendingOrder variable needs to be true to sort Gallery to A-Z by default.
IF(ascendingOrder = true, SortOrder.Ascending,SortOrder.Descending)
in human language "If ascendingOrder variable passing true, please sort all records in Ascending (A-Z) order if ascendingOrder is false, please sort them in Descending (Z-A) order"
To use ascendingOrder and pass true/false to this IF statement, we need to create this variable first somewhere, and in this example, it is done on Screen Property called OnVisible and it is pre-set to true, which always means if the user gets to that screen, his default setting will be Ascending Sort till the user interact with an Icon and change true to false what will alter the behaviour of the IF statement in the result.
to create variable You need to use Set() or UpdateContext() in this case Set() was used
Set(ascendingOrder,true), which creates a variable called ascendingOrder which equals true or ascendingOrder = true
The code in the Icon changes ascendingOrder =true to ascendingorder = false with a click, and that changes the way the Sort work in Gallery.
I really hope I explain it in a way You understand it.