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 when the output is a multi-part file.
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 code |
---|
sort order:column_ref |
Token | Required? | Data Type | Description |
---|
sort | Y | transform | Name of the transform |
order | Y | string | Name of column or columns by which to sort |
Include Page |
---|
| order_sort Parameter |
---|
| order_sort Parameter |
---|
|
Required? | Data Type |
---|
Yes | String (column name) |
Data is sorted based on the data type of the source:
Data Type of Source | Sort Order |
---|
Integer | Numerical |
Decimal | Numerical |
Datetime | Numerical |
All others | String |
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.
| CustId | FirstName | LastName | City | State | LastOrder |
---|
1 | 1001 | Skip | Jones | San Francisco | CA | 25 |
2 | 1002 | Adam | Allen | Oakland | CA | 1099 |
3 | 1003 | David | Wiggins | Oakland | MI | 125.25 |
4 | 1004 | Amanda | Green | Detroit | MI | 452.5 |
5 | 1005 | Colonel | Mustard | Los Angeles | CA | 950 |
6 | 1006 | Pauline | Hall | Saginaw | MI | 432.22 |
7 | 1007 | Sarah | Miller | Cheyenne | WY | 724.22 |
8 | 1008 | Teddy | Smith | Juneau | AK | 852.11 |
9 | 1009 | Joelle | Higgins | Sacramento | CA | 100 |
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:
D trans |
---|
RawWrangle | true |
---|
Type | step |
---|
WrangleText | set col:LastOrder value:numformat(LastOrder, '####.00') |
---|
p01Name | Columns |
---|
p01Value | LastOrder |
---|
p02Name | Formula |
---|
p02Value | numformat(LastOrder, '####.00') |
---|
SearchTerm | Edit column with formula |
---|
|
Now, you're interested in the highest value for your customers' most recent orders. You can apply the following sort:
D trans |
---|
RawWrangle | true |
---|
Type | step |
---|
WrangleText | sort order: -LastOrder |
---|
p01Name | Sort by |
---|
p01Value | -LastOrder |
---|
SearchTerm | Sort rows |
---|
|
Rows are sorted by the LastOrder
column in descending order (largest to smallest):
| CustId | FirstName | LastName | City | State | LastOrder |
---|
2 | 1002 | Adam | Allen | Oakland | CA | 1099.00 |
5 | 1005 | Colonel | Mustard | Los Angeles | CA | 950.00 |
8 | 1008 | Teddy | Smith | Juneau | AK | 852.11 |
7 | 1007 | Sarah | Miller | Cheyenne | WY | 724.22 |
4 | 1004 | Amanda | Green | Detroit | MI | 452.50 |
6 | 1006 | Pauline | Hall | Saginaw | MI | 432.22 |
3 | 1003 | David | Wiggins | Oakland | MI | 125.25 |
9 | 1009 | Joelle | Higgins | Sacramento | CA | 100.00 |
1 | 1001 | Skip | Jones | San Francisco | CA | 25.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 trans |
---|
RawWrangle | true |
---|
Type | step |
---|
WrangleText | sort order: State,City |
---|
p01Name | Sort by |
---|
p01Value | State,City |
---|
SearchTerm | Sort rows |
---|
|
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.
| CustId | FirstName | LastName | City | State | LastOrder |
---|
8 | 1008 | Teddy | Smith | Juneau | AK | 852.11 |
5 | 1005 | Colonel | Mustard | Los Angeles | CA | 950.00 |
2 | 1002 | Adam | Allen | Oakland | CA | 1099.00 |
9 | 1009 | Joelle | Higgins | Sacramento | CA | 100.00 |
1 | 1001 | Skip | Jones | San Francisco | CA | 25.00 |
4 | 1004 | Amanda | Green | Detroit | MI | 452.50 |
3 | 1003 | David | Wiggins | Oakland | MI | 125.25 |
6 | 1006 | Pauline | Hall | Saginaw | MI | 432.22 |
7 | 1007 | Sarah | Miller | Cheyenne | WY | 724.22 |
Include Page |
---|
| EXAMPLE - SOURCEROWNUMBER Function |
---|
| EXAMPLE - SOURCEROWNUMBER Function |
---|
|
D s also |
---|
label | wrangle_transform_sort |
---|
|