Page tree

Release 9.2


Contents:

Our documentation site is moving!

For up-to-date documentation of release 9.2 of Self Managed Designer Cloud, please visit us at https://help.alteryx.com/SMC/r92/.

   

Contents:


NOTE: Transforms are a part of the underlying language, which is not directly accessible to users. This content is maintained for reference purposes only. For more information on the user-accessible equivalent to transforms, see Transformation Reference.

Sorts the dataset based on one or more columns in ascending or descending order. You can also sort based on the order of rows when the dataset was created. 

Limitations:

NOTE: This transform is intended primarily for use in the Transformer page. Sort order may not be preserved in the output files.

  • If you generate a new sample after a sort transform has been applied, the sort order is not retained. You can re-apply the sort step, although the following limitations still apply.
  • Sort order is not preserved on output when the output is a multi-part file.

Basic Usage

sort order:LastName

Output: Dataset is sorted in alphabetically ascending order based on the values in the LastName column, assuming that the values are strings.

Syntax and Parameters

sort order:column_ref

TokenRequired?Data TypeDescription
sortYtransformName of the transform
orderYstringName of column or columns by which to sort

For more information on syntax standards, see Language Documentation Syntax Notes.

order

Identifies the column or set of columns by which the dataset is sorted.
  • Multiple column names can be separated by commas.
  • Ranges of columns cannot be specified.

The order can be reversed by adding a negative sign in front of the column name:

Transformation Name Sort rows
Parameter: Sort by -ProductName

Multi-column sorts:  You can also specify multi-column sorts. The following example sorts first by the inverse order of ProductName and within that sort, rows are sorted by ProductColor:

Transformation Name Sort rows
Parameter: Sort by -ProductName,ProductColor

Sort by original row numbers: As an input value, this parameter also accepts the SOURCEROWNUMBER function, which performs the sort according to the original order of rows when the dataset was created.

Transformation Name Sort rows
Parameter: Sort by $sourcerownumber

See SOURCEROWNUMBER Function.

Usage Notes:

Required?Data Type
YesString (column name)

Data is sorted based on the data type of the source:   

Data Type of SourceSort Order
IntegerNumerical
DecimalNumerical
DatetimeNumerical
All othersString

Examples


Tip: For additional examples, see Common Tasks.

Example - sort methods

Source:

The column without a name identifies the original row numbers. In the data grid, this information is available when you hover over the black dot to the left of a row of data. 

 CustIdFirstNameLastNameCityStateLastOrder
11001SkipJonesSan FranciscoCA25
21002AdamAllenOaklandCA1099
31003DavidWigginsOaklandMI125.25
41004AmandaGreenDetroitMI452.5
51005ColonelMustardLos AngelesCA950
61006PaulineHallSaginawMI432.22
71007SarahMillerCheyenneWY724.22
81008TeddySmithJuneauAK852.11
91009JoelleHigginsSacramentoCA100

Transformation:

First, you might want to clean up the number formatting in the lastOrder column. The following formats the values to always include two digits after the decimal point:

Transformation Name Edit column with formula
Parameter: Columns LastOrder
Parameter: Formula numformat(LastOrder, '####.00')

Now, you're interested in the highest value for your customers' most recent orders. You can apply the following sort:

Transformation Name Sort rows
Parameter: Sort by -LastOrder

Rows are sorted by the LastOrder column in descending order (largest to smallest):

 CustIdFirstNameLastNameCityStateLastOrder
21002AdamAllenOaklandCA1099.00
51005ColonelMustardLos AngelesCA950.00
81008TeddySmithJuneauAK852.11
71007SarahMillerCheyenneWY724.22
41004AmandaGreenDetroitMI452.50
61006PaulineHallSaginawMI432.22
31003DavidWigginsOaklandMI125.25
91009JoelleHigginsSacramentoCA100.00
11001SkipJonesSan FranciscoCA25.00

The above row numbers represent the original order of the rows. Now, you want to get your data geographically organized by sorting by city and state. You can perform multi-column sorts such as the following, which sorts first by State and then by City columns:

Transformation Name Sort rows
Parameter: Sort by State,City

In the generated output, the data is first sorted by the State value. Each set of rows within the same State value is also sorted by the City value.

 CustIdFirstNameLastNameCityStateLastOrder
81008TeddySmithJuneauAK852.11
51005ColonelMustardLos AngelesCA950.00
21002AdamAllenOaklandCA1099.00
91009JoelleHigginsSacramentoCA100.00
11001SkipJonesSan FranciscoCA25.00
41004AmandaGreenDetroitMI452.50
31003DavidWigginsOaklandMI125.25
61006PaulineHallSaginawMI432.22
71007SarahMillerCheyenneWY724.22

Example - Sort by original row numbers

This example illustrates how you can rename columns based on the contents of specified rows.

Source:

You have imported the following racer data on heat times from a CSV file. When loaded in the Transformer page, it looks like the following:

(rowId)column2column3column4column5
1RacerHeat 1Heat 2Heat 3
2Racer X37.2238.2237.61
3Racer Y41.33DQ38.04
4Racer Z39.2739.0438.85

In the above, the (rowId) column references the row numbers displayed in the data grid; it is not part of the dataset. This information is available when you hover over the black dot on the left side of the screen.

Transformation:

You have examined the best performance in each heat according to the sample. You then notice that the data contains headers, but you forget how it was originally sorted. The data now looks like the following:

(rowId)column2column3column4column5
1Racer Y41.33DQ38.04
2RacerHeat 1Heat 2Heat 3
3Racer X37.2238.2237.61
4Racer Z39.2739.0438.85

You can use the following transformation to use the third row as your header for each column:

Transformation Name Rename column with row(s)
Parameter: Option Use row(s) as column names
Parameter: Type Use a single row to name columns
Parameter: Row number 3


Results:

After you have applied the above transformation, your data should look like the following:

(rowId)RacerHeat_1Heat_2Heat_3
3Racer Y41.33DQ38.04
2Racer X37.2238.2237.61
4Racer Z39.2739.0438.85

See Also for EXAMPLE - Rename columns with rows:

See Also for Sort Transform:

There is no content with the specified labels

This page has no comments.