AX2083
Defining the sort for an Axiom query
You can sort the data for an Axiom query in one of two ways:
- A database sort, which sorts the data before it is inserted into the data range (Data sort)
- A spreadsheet column sort, which sorts the data after it is inserted into the data range (Sheet sort)
The database sort only applies when data is first inserted into the data range. It does not apply when updating existing data. If data already exists in a data range, and the refresh behavior is update and insert instead of rebuild, then any new records are inserted at the end of the range, and a sort is not applied.
The spreadsheet column sort applies every time a refresh is performed.
If neither sort setting is defined, the data is sorted by the columns specified in the Sum By setting, in ascending order.
Database sort
To set a database sort, enter one or more database column names into the Data Sort setting in the Sheet Assistant. You can type column names or use the column picker to select and order columns. In the Control Sheet, the corresponding setting is labeled Sort by database columns.
In all cases, the database sort level can use the same column(s) defined as the sum level for the query. If a column is valid to define the sum level, it is also valid to define the sort level, as long as both entries are the same. For more information on valid columns for the sum level, see Defining the sum level for an Axiom query. However, the sort level is not required to be the same as the sum level.
Valid database sort entries depend on the primary table and on other tables included in the query.
When the primary table is a data table and no other data tables are included in the query, the following database columns can be used to define the sort level:
-
Any column in the primary table. You can use fully qualified Table.Column syntax or just the column name. If just the column name is used, and the column is a validated columnA column that has a defined lookup relationship with a column in another table, to define the valid values for the column. For example, if Acct.Acct is assigned as a Lookup Column for GL2014.Acct, then GL2014.Acct is known as a validated column and Acct.Acct is known as a lookup column., the associated lookup table will be assumed (such as
ACCT.ACCT
for an entry ofACCT
). -
Any column in a lookup tableA table that is the target of a Lookup Column relationship in another table. For example, if the column GL2018.Acct links to the column Acct.Acct, then the Acct reference table is known as a "lookup reference table".. You must use fully qualified Table.Column syntax. Multiple levels of lookups can be used.
When the primary table is a data table and additional data tables are included in the query, the following database columns can be used to define the sort level:
-
Any shared validated columnA column that has a defined lookup relationship with a column in another table, to define the valid values for the column. For example, if Acct.Acct is assigned as a Lookup Column for GL2014.Acct, then GL2014.Acct is known as a validated column and Acct.Acct is known as a lookup column. in the data tables, key or non-key. You can use column-only syntax (such as
DEPT
, which assumes the DEPT table in this context), or fully qualified Table.Column syntax (such asDEPT.Dept
). -
Any column in a shared lookup tableA table that is the target of a Lookup Column relationship in another table. For example, if the column GL2018.Acct links to the column Acct.Acct, then the Acct reference table is known as a "lookup reference table".. You must use fully qualified Table.Column syntax (such as
DEPT.Region
orACCT.Category
). Multiple levels of lookups can be used. -
Any column in any of the data tables included in the query. You must use fully qualified Table.Column syntax (such as
GL2019.TOT
to sort by total values in that table). If you enter just a column name, then the entry will be interpreted as a column on the primary table. -
Any shared non-validated column in the data tables, key or non-key—but only if the same column is also used as the sum level. In this case you must specify only the column name—do not use fully qualified syntax (such as
Detail
where all data tables contain a non-validated column named Detail). (Note that if the shared non-validated column is not used as the sum level, and you enter just the column name, then the entry will be interpreted as the column on the primary table.)
If the primary table is a reference table, the following database columns can be used to define the sort level:
-
Any column in the primary table. You can use fully qualified Table.Column syntax, or just the column name. If just the column name is used, and the column is a validated columnA column that has a defined lookup relationship with a column in another table, to define the valid values for the column. For example, if Acct.Acct is assigned as a Lookup Column for GL2014.Acct, then GL2014.Acct is known as a validated column and Acct.Acct is known as a lookup column., the associated lookup table will be assumed.
-
Any column in a lookup reference table. You must use fully qualified Table.Column syntax. Multiple levels of lookups can be used.
If the primary table is a reference table and one or more data tables are included in the query, then the following requirements apply to the allowed sort level entries:
-
If the sort level is a column in the primary table, and that column is a validated column, then you must use fully qualified Table.Column syntax.
For example, if the primary table Dept contains a validated column Region, and you want to use that column as the sort level, then you must enter this as
Dept.Region
. If instead the entry is justRegion
, then the lookup column will be assumed (such asRegion.Region
), which will make the query invalid because the table Region cannot be joined to the data table. -
If the sort level is a column in a lookup reference table, the entry must use multiple-level lookup syntax that starts with the primary table.
For example, if the primary table Dept contains a validated column Region, and you want to use
Region.RegionType
in the lookup table as the sort level, then you must enter this asDept.Region.RegionType
. If instead the entry is justRegion.RegionType
, this will make the query invalid because the table Region cannot be joined to the data table.
You can specify multiple columns, separated by commas. For example, ACCT.ACCT,DEPT.DEPT
sorts first by account, then by department, both in ascending order (the default).
If you have defined a unique name for a column that uses special syntax (such as AxAggregate or column filters), then you can use that unique name to define the sort level as long as the column would otherwise be valid for use as detailed previously.
Spreadsheet column sort
To set a spreadsheet sort, enter one or more spreadsheet column letters into the Sheet Sort setting in the Sheet Assistant. In the Control Sheet, the corresponding setting is labeled Sort results by these columns.
You can sort by any column in the sheet. You can specify multiple columns, separated by commas. For example, C,D
sorts first by column C, then by column D, both in ascending order (the default).
NOTE: The spreadsheet column sort is only supported for use with standard vertical Axiom queries. This setting is ignored for horizontal queries.
Keep in mind that the column sort is applied every time the data is refreshed, which may impact performance unnecessarily. Also, certain queries are not suited to a column sort—for example, when inserting rows in a plan file that use a multi-row calc method.
Specifying ascending or descending order
You can specify ascending or descending sort order by placing Asc
or Desc
after the database column name or the spreadsheet column letter. If omitted, the sort is ascending order by default. For example:
Acct Asc; NYB1 Desc
This example sorts first by accounts in ascending order, then by Next Year Budget values in descending order.
AX2083