---
title: "SORTBY function in Excel: syntax and examples | PracticeExcel"
description: "How to use SORTBY in Excel 365: sort by a column you do not show, sort by two columns, and rank a list from best to worst."
canonical_url: "https://practiceexcelonline.com/functions/sortby"
locale: en
meta:
  "og:description": "How to use SORTBY in Excel 365: sort by a column you do not show, sort by two columns, and rank a list from best to worst."
  "og:image": "https://practiceexcelonline.com/_og/d/c_Page%2Ctitle_~U09SVEJZIGZ1bmN0aW9uIGluIEV4Y2VsOiBzeW50YXggYW5kIGV4YW1wbGVz%2Cdescription_~SG93IHRvIHVzZSBTT1JUQlkgaW4gRXhjZWwgMzY1OiBzb3J0IGJ5IGEgY29sdW1uIHlvdSBkbyBub3Qgc2hvdywgc29ydCBieSB0d28gY29sdW1ucywgYW5kIHJhbmsgYSBsaXN0IGZyb20gYmVzdCB0byB3b3JzdC4%2Ceyebrow_Excel%2Bfunctions%2Csite_practiceexcel%2Ccode_~U09SVEJZKGFycmF5LCBieV9hcnJheTEsIFtzb3J0X29yZGVyMV0sIFtieV9hcnJheTIsIHNvcnRfb3JkZXIyXSwgLi4uKQ%2Cp_Ii9mdW5jdGlvbnMvc29ydGJ5Ig%2Cs_Nkg0TwDvFkpQT4Wc.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "SORTBY function in Excel: syntax and examples | PracticeExcel"
  "twitter:image": "https://practiceexcelonline.com/_og/d/c_Page%2Ctitle_~U09SVEJZIGZ1bmN0aW9uIGluIEV4Y2VsOiBzeW50YXggYW5kIGV4YW1wbGVz%2Cdescription_~SG93IHRvIHVzZSBTT1JUQlkgaW4gRXhjZWwgMzY1OiBzb3J0IGJ5IGEgY29sdW1uIHlvdSBkbyBub3Qgc2hvdywgc29ydCBieSB0d28gY29sdW1ucywgYW5kIHJhbmsgYSBsaXN0IGZyb20gYmVzdCB0byB3b3JzdC4%2Ceyebrow_Excel%2Bfunctions%2Csite_practiceexcel%2Ccode_~U09SVEJZKGFycmF5LCBieV9hcnJheTEsIFtzb3J0X29yZGVyMV0sIFtieV9hcnJheTIsIHNvcnRfb3JkZXIyXSwgLi4uKQ%2Cp_Ii9mdW5jdGlvbnMvc29ydGJ5Ig%2Cs_Nkg0TwDvFkpQT4Wc.png"
---

> Index of every page on this site: [llms.txt](https://practiceexcelonline.com/llms.txt)

# **The SORTBY function**

Sorts a range by the values in another range, which need not be part of the result. Add more by-range and order pairs to break ties.

=

SORTBY(

## **Syntax**

```
SORTBY(array, by_array1, [sort_order1], [by_array2, sort_order2], ...)
```

<dl><dt>**array **</dt>
<dd>The range to sort and return.</dd>
<dt>**by_array1 **</dt>
<dd>The range to sort by, one value per row of array.</dd>
<dt>**sort_order1 **(optional)</dt>
<dd>1 or left out for smallest to largest, -1 for largest to smallest.</dd>
<dt>**by_array2, sort_order2 **(optional)</dt>
<dd>More ranges and orders, used when the earlier ones tie.</dd></dl>

## **Examples**

E1`=SORTBY(<sup>1</sup>A2:A5,<sup>2</sup>C2:C5,<sup>3</sup>-1)`

|  | A | B | C | D | E |
| --- | --- | --- | --- | --- | --- |
| 1 | Name | Team | Sales |  | **Ben** |
| 2 | Maya | East | 320 |  | **Maya** |
| 3 | Ben | West | 450 |  | **Ava** |
| 4 | Zoe | East | 180 |  | **Zoe** |
| 5 | Ava | West | 275 |  | |

**In plain words:** Sort <sup>1</sup>the names in A2:A5 by <sup>2</sup>the sales in C2:C5, <sup>3</sup>largest first.

E1=SORTBY(A2:C5,B2:B5,1,C2:C5,-1)

|  | A | B | C | D | E | F | G |
| --- | --- | --- | --- | --- | --- | --- | --- |
| 1 | Name | Team | Sales |  | **Maya** | **East** | **320** |
| 2 | Maya | East | 320 |  | **Zoe** | **East** | **180** |
| 3 | Ben | West | 450 |  | **Ben** | **West** | **450** |
| 4 | Zoe | East | 180 |  | **Ava** | **West** | **275** |
| 5 | Ava | West | 275 |  |  |  | |

## **Questions**

<details>

<summary>

### What is the difference between SORT and SORTBY?

</summary>

SORT sorts by a column number inside the range. SORTBY sorts by a separate range, so the column you sort by does not have to be in the result, and several sort levels are easy to add.

</details>

<details>

<summary>

### How do I sort by two columns?

</summary>

Give SORTBY two pairs, as in =SORTBY(A2:C5,B2:B5,1,C2:C5,-1). It sorts by team first and, inside each team, by sales from highest to lowest.

</details>

## **Related functions**

- [**SORT**](https://practiceexcelonline.com/functions/sort)
- [**FILTER**](https://practiceexcelonline.com/functions/filter)
- [**XLOOKUP**](https://practiceexcelonline.com/functions/xlookup)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://practiceexcelonline.com/#identity","@type":"Organization","name":"PracticeExcel","url":"https://practiceexcelonline.com/","logo":{"@id":"https://practiceexcelonline.com/#logo"}},{"@id":"https://practiceexcelonline.com/#website","@type":"WebSite","inLanguage":"en-US","name":"PracticeExcel","url":"https://practiceexcelonline.com/","alternateName":["Practice Excel Online","PracticeExcelOnline.com"],"publisher":{"@id":"https://practiceexcelonline.com/#identity"},"workTranslation":{"@id":"https://excelopgaver.dk/#website"}},{"@id":"https://practiceexcelonline.com/functions/sortby#webpage","description":"How to use SORTBY in Excel 365: sort by a column you do not show, sort by two columns, and rank a list from best to worst.","name":"SORTBY function in Excel: syntax and examples","url":"https://practiceexcelonline.com/functions/sortby","@type":["WebPage","FAQPage"],"breadcrumb":{"@id":"https://practiceexcelonline.com/functions/sortby#breadcrumb"},"isPartOf":{"@id":"https://practiceexcelonline.com/#website"},"mainEntity":[{"@id":"https://practiceexcelonline.com/functions/sortby#/schema/question/1"},{"@id":"https://practiceexcelonline.com/functions/sortby#/schema/question/2"}],"potentialAction":[{"@type":"ReadAction","target":["https://practiceexcelonline.com/functions/sortby"]}],"primaryImageOfPage":{"@id":"https://practiceexcelonline.com/#logo"}},{"@id":"https://practiceexcelonline.com/functions/sortby#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Home","item":"https://practiceexcelonline.com","position":1},{"@type":"ListItem","name":"Excel functions","item":"https://practiceexcelonline.com/functions","position":2},{"@type":"ListItem","name":"SORTBY function in Excel: syntax and examples","position":3}]},{"@id":"https://practiceexcelonline.com/functions/sortby#article","description":"How to use SORTBY in Excel 365: sort by a column you do not show, sort by two columns, and rank a list from best to worst.","headline":"SORTBY function in Excel: syntax and examples","inLanguage":"en-US","thumbnailUrl":"https://practiceexcelonline.com/_og/d/c_Page%2Ctitle_~U09SVEJZIGZ1bmN0aW9uIGluIEV4Y2VsOiBzeW50YXggYW5kIGV4YW1wbGVz%2Cdescription_~SG93IHRvIHVzZSBTT1JUQlkgaW4gRXhjZWwgMzY1OiBzb3J0IGJ5IGEgY29sdW1uIHlvdSBkbyBub3Qgc2hvdywgc29ydCBieSB0d28gY29sdW1ucywgYW5kIHJhbmsgYSBsaXN0IGZyb20gYmVzdCB0byB3b3JzdC4%2Ceyebrow_Excel%2Bfunctions%2Csite_practiceexcel%2Ccode_~U09SVEJZKGFycmF5LCBieV9hcnJheTEsIFtzb3J0X29yZGVyMV0sIFtieV9hcnJheTIsIHNvcnRfb3JkZXIyXSwgLi4uKQ%2Cp_Ii9mdW5jdGlvbnMvc29ydGJ5Ig%2Cs_Nkg0TwDvFkpQT4Wc.png","@type":["Article","TechArticle"],"author":{"@id":"https://practiceexcelonline.com/#identity"},"image":{"@id":"https://practiceexcelonline.com/#/schema/image/1"},"isPartOf":{"@id":"https://practiceexcelonline.com/functions/sortby#webpage"},"mainEntityOfPage":{"@id":"https://practiceexcelonline.com/functions/sortby#webpage"},"publisher":{"@id":"https://practiceexcelonline.com/#identity"}},{"@id":"https://practiceexcelonline.com/functions/sortby#/schema/question/1","@type":"Question","inLanguage":"en-US","name":"What is the difference between SORT and SORTBY?","acceptedAnswer":{"@type":"Answer","text":"SORT sorts by a column number inside the range. SORTBY sorts by a separate range, so the column you sort by does not have to be in the result, and several sort levels are easy to add."}},{"@id":"https://practiceexcelonline.com/functions/sortby#/schema/question/2","@type":"Question","inLanguage":"en-US","name":"How do I sort by two columns?","acceptedAnswer":{"@type":"Answer","text":"Give SORTBY two pairs, as in =SORTBY(A2:C5,B2:B5,1,C2:C5,-1). It sorts by team first and, inside each team, by sales from highest to lowest."}},{"@id":"https://practiceexcelonline.com/#logo","@type":"ImageObject","caption":"PracticeExcel","contentUrl":"https://practiceexcelonline.com/brand/practiceexcel/icon-512.png","inLanguage":"en-US","url":"https://practiceexcelonline.com/brand/practiceexcel/icon-512.png"},{"@id":"https://practiceexcelonline.com/#/schema/image/1","@type":"ImageObject","contentUrl":"https://practiceexcelonline.com/_og/d/c_Page%2Ctitle_~U09SVEJZIGZ1bmN0aW9uIGluIEV4Y2VsOiBzeW50YXggYW5kIGV4YW1wbGVz%2Cdescription_~SG93IHRvIHVzZSBTT1JUQlkgaW4gRXhjZWwgMzY1OiBzb3J0IGJ5IGEgY29sdW1uIHlvdSBkbyBub3Qgc2hvdywgc29ydCBieSB0d28gY29sdW1ucywgYW5kIHJhbmsgYSBsaXN0IGZyb20gYmVzdCB0byB3b3JzdC4%2Ceyebrow_Excel%2Bfunctions%2Csite_practiceexcel%2Ccode_~U09SVEJZKGFycmF5LCBieV9hcnJheTEsIFtzb3J0X29yZGVyMV0sIFtieV9hcnJheTIsIHNvcnRfb3JkZXIyXSwgLi4uKQ%2Cp_Ii9mdW5jdGlvbnMvc29ydGJ5Ig%2Cs_Nkg0TwDvFkpQT4Wc.png","inLanguage":"en-US","url":"https://practiceexcelonline.com/_og/d/c_Page%2Ctitle_~U09SVEJZIGZ1bmN0aW9uIGluIEV4Y2VsOiBzeW50YXggYW5kIGV4YW1wbGVz%2Cdescription_~SG93IHRvIHVzZSBTT1JUQlkgaW4gRXhjZWwgMzY1OiBzb3J0IGJ5IGEgY29sdW1uIHlvdSBkbyBub3Qgc2hvdywgc29ydCBieSB0d28gY29sdW1ucywgYW5kIHJhbmsgYSBsaXN0IGZyb20gYmVzdCB0byB3b3JzdC4%2Ceyebrow_Excel%2Bfunctions%2Csite_practiceexcel%2Ccode_~U09SVEJZKGFycmF5LCBieV9hcnJheTEsIFtzb3J0X29yZGVyMV0sIFtieV9hcnJheTIsIHNvcnRfb3JkZXIyXSwgLi4uKQ%2Cp_Ii9mdW5jdGlvbnMvc29ydGJ5Ig%2Cs_Nkg0TwDvFkpQT4Wc.png"}]}
```

## Sitemap

See the full [sitemap](https://practiceexcelonline.com/sitemap.md) for all pages.
