---
schema_version: "1"
id: 17a8f38b39068b8f46bebfddf6f0d543775e512b7c7fdf0b7069959a47db83c9
title: sort
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/sales/264-0-0/spiff_function_ref_sort.md
canonical_url: https://help.salesforce.com/s/articleView?id=sales.spiff_function_ref_sort.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: e5cc372b5e89cb9b6198add4d9ccd76f447a426194d54160e4fc0c156c8af1bf
description: Organizes records in a Salesforce Spiff data filter by a date, string value, or number value and returns a list of sorted records.
products:
  - Sales Cloud
  - Sales Enablement
release: "264"
---
# sort

Organizes records in a Salesforce Spiff data filter by a date, string value, or number value and returns a list of sorted records.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: both Salesforce Classic (not available in all orgs) and Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Enterprise</strong>, <strong>Unlimited</strong>, and <strong>Developer</strong> Editions</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available for an additional cost in: <strong>Professional</strong> Edition with Web Services API Enabled</td></tr></tbody></table>

## Syntax

```
sort(scope, sort_criteria, direction)
```

## Arguments

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:20%">
          <col style="width:20%">
          <col style="width:60%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d90716e102">Argument</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d90716e105">Required?</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d90716e108">Description</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Argument" class="slds-cell-wrap" style="vertical-align:top;" headers="d90716e102 "><samp class="parmname">scope</samp></td>

            <td data-label="Required?" class="slds-cell-wrap" style="vertical-align:top;" headers="d90716e105 ">Required</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d90716e108 ">A data filter or list to sort.</td>

          </tr>
          <tr class="">
            <td data-label="Argument" class="slds-cell-wrap" style="vertical-align:top;" headers="d90716e102 "><samp class="parmname">sort_criteria</samp></td>

            <td data-label="Required?" class="slds-cell-wrap" style="vertical-align:top;" headers="d90716e105 ">Required</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d90716e108 ">An expression that specifies the field or calculation to sort the data filter or list by.</td>

          </tr>
          <tr class="">
            <td data-label="Argument" class="slds-cell-wrap" style="vertical-align:top;" headers="d90716e102 "><samp class="parmname">direction</samp></td>

            <td data-label="Required?" class="slds-cell-wrap" style="vertical-align:top;" headers="d90716e105 ">Optional</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d90716e108 ">
              <p>An integer that specifies how the data is sorted.
              </p>
              <ul>
                <li>To sort the data in ascending order, use <code>1</code>. This value is the default.</li>

                <li>To sort the data is descending order, use <code>-1</code>.</li>

              </ul>
            </td>

          </tr>
        </tbody>
      </table>

## Example

Sort records in the ClosedInPeriod data filter by ARR\_\_c field value in ascending order.

```
=sort(ClosedInPeriod, ARR__c, 1)
```

Sort records in the ClosedInPeriod data filter by CloseDate in descending order.

```
=sort(ClosedInPeriod, CloseDate, -1)
```

![Important](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-sales-sales_performance_management-264-0-0-production-enus/b1f2feb4-26b8-444f-97f7-be2349869d93/images/icon_important.png)

Important The `sort()` function doesn't work with lists of primitive values, such as a list of raw numbers.

#### See Also

- [choose](https://help.salesforce.com/s/articleView?id=sales.spiff_function_ref_choose.htm&release=264.0.0&type=5 "Returns a value from a list based on a specified index in Salesforce Spiff. List values in Spiff aren't sorted by any default order. To make sure that you select the appropriate value, combine this function with sort() so that you sort the list values before you select a specific index.")
- [transform\_list](https://help.salesforce.com/s/articleView?id=sales.spiff_function_ref_transform_list.htm&release=264.0.0&type=5 "Applies an expression to each record in a data filter in Salesforce Spiff and returns a new list with the results. For example, identify a specific field from a list of records and return a list of the values for only that field from those records.")