First Name |
Last Name |
Age |
<sort field> |
John |
Doe |
33 |
1 |
Jane |
Roe |
32 |
0 |
Joan |
Coe |
34 |
2 |
Jim |
Poe |
31 |
3 |
which sorted would become
First Name |
Last Name |
Age |
<sort field> |
Jane |
Roe |
32 |
0 |
John |
Doe |
33 |
1 |
Joan |
Coe |
34 |
2 |
Jim |
Poe |
31 |
3 |
and the result would be the table sorted by that new field:
First Name |
Last Name |
Age |
Jane |
Roe |
32 |
John |
Doe |
33 |
Joan |
Coe |
34 |
Jim |
Poe |
31 |
Taking it further, since the second argument can be any Power Fx expression, it doesn't need to even reference any field from the table. A call to Sort(Contacts, Rand()) would be similar to a call to Shuffle(Contacts) - the order would be randomized. Or a call to Sort(Contacts, "hello") would generate an internal table similar to
First Name |
Last Name |
Age |
<sort field> |
John |
Doe |
33 |
"hello" |
Jane |
Roe |
32 |
"hello" |
Joan |
Coe |
34 |
"hello" |
Jim |
Poe |
31 |
"hello" |
Notice that any order of the entries returned by this function call would be technically correct - since the sort field is always "hello", then no record is "greater" or "smaller" than the other (I believe today the result is the original order, but I wouldn't rely on that).
And that's the same case as a call to Sort(Contacts, SortOrder.Ascending). The value of SortOrder.Ascending is being used as the sort field for all records (since it's being used in the second argument, not the third one), so in this case they all have the same sort order. And that's why the call doesn't produce any error. It's doing exactly what the expression asked it to do, even though it likely isn't the intent of the author. We may add some warnings in the future to prevent this from being a surprise, though.