Page tree

 

Support | BlogContact Us | 844.332.2821

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

D toc

Excerpt

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:

Info

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 in the following conditions:
    • Output is a multi-part file.
    • Output is generated by a running environment that does not support sorting.

D s
snippetBasic

D code
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.

D s
snippetParameters
D code

sort order:column_ref

ParameterRequired?Transform BuilderData TypeDescription
orderYSort bystringName of column or columns by which to sort

d-s-lang-notes

order

Include Page
order_sort Parameter
order_sort Parameter

D s
snippetusage

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

D s
snippetExamples

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

Transform:

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:

D code

set col:LastOrder value:NUMFORMAT(LastOrder, '####.00')

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

D code

sort order: -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:

D code

sort order: 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

To revert to the original sort order, use the following ORIGINALORDER function:

D code

sort order:ORIGINALORDER()

Example - Sort by original row numbers

Include Page
EXAMPLE - SOURCEROWNUMBER Function
EXAMPLE - SOURCEROWNUMBER Function

D s also
labelwrangle_transform_sort