Block reference / Data

Sort data

Sort the table's rows or a list variable, up or down.

In both appsWarpX BrowserWarpX Phone

Sort data puts a list in order: the rows of the workflow's table, or a list held in a variable. Sort plain values as they are, or sort objects by their properties, such as columns. With more than one property, the first sets the order and the others break ties.

The Sort data block's settings, filled in as in the example below.

Settings

Data source

Sort the workflow's table, or a list in a variable.

ExampleTable
Variable namewhen Data source is Variable

The variable to sort. It must hold a list.

Exampleprices
Sort by the item's property

Turn this on to sort objects, such as table rows, by a property. Off, the items are compared as they are, which suits a list of numbers or text.

ExampleChecked
Add propertywhen Sort by the item's property is on

Each row is a property name (a column name for the table) and Ascending or Descending. You can add up to three. The first row sets the order. Each row below it only orders the items the rows above left tied, in its own direction.

Example
rating | Descending
reviews | Descending
Assign to variable

Also store the sorted list in a variable.

ExampleUnchecked
Variable namewhen Assign to variable is ticked

The variable that receives the sorted list.

ExampletopProducts
Insert to table

Put the whole sorted list into one cell of the table.

ExampleUnchecked
Select columnwhen Insert to table is ticked

The column that receives the list.

Examplesorted

Every block also has the shared block settings — a description, Disable block and what to do on an error. Fields that take text accept data from earlier blocks.

What it hands on

The source is sorted where it is: the table's rows, or the variable's list, change order. The sorted list also goes on as {{prevBlockData}}, and to the variable or column you chose.

Example: Put the best rated products first, most reviewed first among equals

  1. Start
  2. Open URL
  3. Get text
  4. Sort data
  5. Google Sheets
Where Sort data sits in the example workflow.
  1. In the workflow's table, add columns product, rating and reviews, and set the Data type of rating and reviews to Number.
  2. Fill them from the page with Get text and Insert to table.
  3. Add Sort data and keep Data source on Table.
  4. Turn on Sort by the item's property. Click Add property, type rating and choose Descending.
  5. Click Add property again, type reviews and choose Descending.
  6. Send the table on with Google Sheets. The highest rated products come first, and products with the same rating are ordered by their number of reviews.

Good to know

  • When an item has no value for a property, the whole item is compared in its place, which gives no useful order. Make sure every row has a value in the columns you sort by.
  • Text is compared as text, so 100 comes before 25. Give a column the Number data type when you want number order.
  • Sorting table rows with Sort by the item's property off leaves them as they were: rows are objects and do not compare.
  • A source that is not a list stops the block, for example Can't sort data with "string" data type.

See also

  • Data mapping — Copy chosen properties of the table or a variable into new names.
  • Loop data — Run the blocks after it once for each row, number, list item or element.
  • Google Sheets — Read rows from a Google Sheet, keep only the ones you want, or write, append and clear cells.