sort

Sorting rows can make subsequent computations easier and more efficient.

Use the"sort" directive to order rows of data by values in selected columns. Like other transformative directives, the "from" directive is required to work.

๐Ÿ“˜

The "sort" directive is a transformative directive.

The "sort" directive requires a declared "from" directive to be present in the same comment.

For instance, to sort the "Customer" worksheet rows by "Last name" descending with ties broken by "First name" ascending place the following directive in a comment in the "OrderedByLastName" worksheet.

pebblestream:from(Customer)
pebblestream:sort("Last name":desc, "First name":asc, ...)

The "sort" directive cannot be used with the "group" directive.

โ—๏ธ

Important!

The "sort" directive cannot be combined with the "group" directive

Example 1

Consider the "Accounts" worksheet

IDBalance
544
140
8848
212

Using the following directive declaration in the "Sorted" worksheet

pebblestream:from(Accounts)
pebblestream:sort("ID")

results in the following:

IDBalance
140
312
544
8848

Example 2

Consider sorting a Transactions worksheet

FirstLastDate
JohnJones9/2/2020
AdamJones1/1/2000
CathyAlbertson5/7/1990
JohnJones5/4/2013

using the directive declaration below

pebblestream:from(Transactions)
pebblestream:sort("Last", "First", "Date":desc)

to obtain the SortedTransactions worksheet:

FirstLastDate
CathyAlbertson5/7/1990
AdamJones1/1/2000
JohnJones9/2/2020
JohnJones5/4/2013