> For the complete documentation index, see [llms.txt](https://olddocs.exivity.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://olddocs.exivity.io/data-pipelines/transform/language/sort.md).

# sort

## Overview

The `sort` statement is used to re-order the rows in usage data

## Syntax

**`sort`***`dset.id [desc|descending]`***`using|by`***`column_name [column_name ...]`*

## Details

The `sort` statement will reorder the usage records in the specified DSET using one or more column names as the keys to sort by.

By default the sort will be done in ascending order but if the optional *desc* keyword is present after the DSET ID then the rows will be sorted in descending order.

Any number of columns to sort by may be specified but any given column name may only appear once in the list, the column names must not be fully qualified, and all the specified columns must exist in the data to be sorted.

## Examples

Given the following data imported as the dset `example.sort`:

```
account,account2,service,quantity,rate,cogs,interval,instance,ref1,ref2
Account1,Subaccount1,ServiceX,100,1,0.5,monthly,Instance,zebra,echo
Account1,Subaccount2,ServiceY,100,1,0.5,daily,Instance2,delta,echo
Account1,Subaccount2,ServiceY,100,1,0.5,daily,Instance2,zebra,alpha
Account1,Subaccount2,ServiceY,100,1,0.5,daily,Instance2,delta,echo
Account1,Subaccount3,ServiceZ,100,1,0.5,individually,Instance3,charlie,zebra
Account1,Subaccount3,ServiceZ,100,1,0.5,individually,Instance3,charlie,bravo
Account1,Subaccount3,ServiceZ,100,1,0.5,individually,Instance3,charlie,romeo
Account2,Subaccount4,ServiceX,100,1,0.5,monthly,Instance,golf,tango
Account2,Subaccount4,ServiceY,100,1,0.5,daily,Instance2,sierra,papa
Account2,Subaccount4,ServiceZ,100,1,0.5,individually,Instance3,xray,papa
```

... the following statement:

`sort example.sort by ref1 ref2`

... will reorder the usage records as follows.

```
account,account2,service,quantity,rate,cogs,interval,instance,ref1,ref2
Account1,Subaccount3,ServiceZ,100,1,0.5,individually,Instance3,charlie,bravo
Account1,Subaccount3,ServiceZ,100,1,0.5,individually,Instance3,charlie,romeo
Account1,Subaccount3,ServiceZ,100,1,0.5,individually,Instance3,charlie,zebra
Account1,Subaccount2,ServiceY,100,1,0.5,daily,Instance2,delta,echo
Account1,Subaccount2,ServiceY,100,1,0.5,daily,Instance2,delta,echo
Account2,Subaccount4,ServiceX,100,1,0.5,monthly,Instance,golf,tango
Account2,Subaccount4,ServiceY,100,1,0.5,daily,Instance2,sierra,papa
Account2,Subaccount4,ServiceZ,100,1,0.5,individually,Instance3,xray,papa
Account1,Subaccount2,ServiceY,100,1,0.5,daily,Instance2,zebra,alpha
Account1,Subaccount1,ServiceX,100,1,0.5,monthly,Instance,zebra,echo
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://olddocs.exivity.io/data-pipelines/transform/language/sort.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
