Sort data in the code representation of a data model
You can sort data in a table when creating or managing a data model as code using the sort array in the table element.
By specifying how data is sorted, you can control how tables created using the Create a data model from a code representation endpoint are presented to users in the UI. This allows you to programmatically create tables according to common user needs, such as presenting data in reverse-chronological order.
Example representation with sorted columns
The following example shows a JSON representation of a data model with a table that has an ascending sort order applied to the columns START_DATE and DURATION. This produces a table with rows sorted first by START_DATE with the earliest dates first. For any rows with the same START_DATE, they are sorted by DURATION in ascending order. For more information on sorting data in the Sigma UI, see Customize the sort order of table elements.
Full JSON representation with sort
{
"dataModelId": "f2c648bc-0ea5-4eab-be4e-73900d50d84a",
"name": "sort",
"url": "https://aws-api.sigmacomputing.com/org-name/data-model/sort-JDEWh0IJtkmfpYrf6NEg9",
"documentVersion": 2,
"latestDocumentVersion": 2,
"ownerId": "LM0ctRV4v2nxVHOtFP8lT1gB6VxXu",
"folderId": "34280d24-0894-4a57-9cc6-c9f1dd82872c",
"createdBy": "LM0ctRV4v2nxVHOtFP8lT1gB6VxXu",
"updatedBy": "LM0ctRV4v2nxVHOtFP8lT1gB6VxXu",
"createdAt": "2026-03-25T17:45:12.602Z",
"updatedAt": "2026-03-25T17:51:50.652Z",
"schemaVersion": 1,
"pages": [
{
"id": "T9kb6kwy8j",
"name": "Page 1",
"elements": [
{
"id": "YeDKCh8akL",
"kind": "table",
"source": {
"connectionId": "253b1393-d8fe-4190-b3bc-8c235fffcaf9",
"kind": "warehouse-table",
"path": [
"EXAMPLES",
"BIKES",
"TRIP"
]
},
"columns": [
{
"id": "inode-8msHptIwZ86qB4JPcIdql8/ID",
"formula": "[TRIP/Id]"
},
{
"id": "inode-8msHptIwZ86qB4JPcIdql8/DURATION",
"formula": "[TRIP/Duration]"
},
{
"id": "inode-8msHptIwZ86qB4JPcIdql8/START_DATE",
"formula": "[TRIP/Start Date]"
},
{
"id": "inode-8msHptIwZ86qB4JPcIdql8/START_STATION_NAME",
"formula": "[TRIP/Start Station Name]"
},
{
"id": "inode-8msHptIwZ86qB4JPcIdql8/START_STATION_ID",
"formula": "[TRIP/Start Station Id]"
},
{
"id": "inode-8msHptIwZ86qB4JPcIdql8/END_DATE",
"formula": "[TRIP/End Date]"
},
{
"id": "inode-8msHptIwZ86qB4JPcIdql8/END_STATION_NAME",
"formula": "[TRIP/End Station Name]"
},
{
"id": "inode-8msHptIwZ86qB4JPcIdql8/END_STATION_ID",
"formula": "[TRIP/End Station Id]"
},
{
"id": "inode-8msHptIwZ86qB4JPcIdql8/BIKE_ID",
"formula": "[TRIP/Bike Id]"
},
{
"id": "inode-8msHptIwZ86qB4JPcIdql8/SUBSCRIPTION_TYPE",
"formula": "[TRIP/Subscription Type]"
},
{
"id": "inode-8msHptIwZ86qB4JPcIdql8/ZIP_CODE",
"formula": "[TRIP/Zip Code]"
}
],
"order": [
"inode-8msHptIwZ86qB4JPcIdql8/ID",
"inode-8msHptIwZ86qB4JPcIdql8/DURATION",
"inode-8msHptIwZ86qB4JPcIdql8/START_DATE",
"inode-8msHptIwZ86qB4JPcIdql8/START_STATION_NAME",
"inode-8msHptIwZ86qB4JPcIdql8/START_STATION_ID",
"inode-8msHptIwZ86qB4JPcIdql8/END_DATE",
"inode-8msHptIwZ86qB4JPcIdql8/END_STATION_NAME",
"inode-8msHptIwZ86qB4JPcIdql8/END_STATION_ID",
"inode-8msHptIwZ86qB4JPcIdql8/BIKE_ID",
"inode-8msHptIwZ86qB4JPcIdql8/SUBSCRIPTION_TYPE",
"inode-8msHptIwZ86qB4JPcIdql8/ZIP_CODE"
],
"sort": [
{
"columnId": "inode-8msHptIwZ86qB4JPcIdql8/START_DATE",
"direction": "ascending",
"nulls": "last"
},
{
"columnId": "inode-8msHptIwZ86qB4JPcIdql8/DURATION",
"direction": "ascending",
"nulls": "last"
}
]
}
]
}
]
}Representing sort order
In this representation, the sort order is specified in the sort array of the table element. The sort array contains objects that define which columns to sort by and in what direction. In this example, there is a custom sort applied to the table that sorts first by START_DATE in ascending order, and then by DURATION in ascending order. Both place null values last in the order.
Sort representation
...
"sort": [
{
"columnId": "inode-8msHptIwZ86qB4JPcIdql8/START_DATE",
"direction": "ascending",
"nulls": "last"
},
{
"columnId": "inode-8msHptIwZ86qB4JPcIdql8/DURATION",
"direction": "ascending",
"nulls": "last"
}
]
...Updated about 13 hours ago
