ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Dynamic arrays
  3. Sort and Filter Together With One Formula

Sort and Filter Together With One Formula

By ExcelReady Team·Updated November 2, 2026·7 min read

The short answer

To sort and filter with one formula, put FILTER inside SORT: =SORT(FILTER(A2:D8,B2:B8="North"),4,-1). FILTER keeps the rows that match, and SORT puts them in order by the 4th column, largest first. The result spills into the cells below and updates when the data changes. It needs Excel 2021 or Microsoft 365.

Key takeaways

  • Nest FILTER inside SORT: =SORT(FILTER(data, condition), column, order).
  • The sort column number counts columns in the filtered result, not the sheet.
  • Use -1 for largest to smallest and 1 (or leave it out) for smallest to largest.
  • Multiply conditions for AND, add them for OR, and use {2,4},{1,-1} to sort by two columns.
  • SORT and FILTER need Excel 2021 or Microsoft 365; older versions show #NAME?.
On this page+
  1. The sort and filter formula pattern
  2. Filter one region and sort by sales
  3. Why FILTER goes inside SORT
  4. Add more conditions: AND and OR
  5. Sort by two columns
  6. Return the top N matching rows
  7. Common errors and how to fix them
  8. Practise it

A sort and filter formula in Excel puts FILTER inside SORT, so one cell returns only the rows you want, already in order. =SORT(FILTER(A2:D8,B2:B8="North"),4,-1) lists the North sales from largest to smallest, and it updates by itself when the data changes. This guide is for anyone who builds reports or dashboards in Excel 2021 or Microsoft 365 and is tired of clicking the filter and sort buttons again every week.

The sort and filter formula pattern#

The pattern has two layers. FILTER chooses the rows, and SORT puts them in order:

Excel formula
=SORT(FILTER(array, include, [if_empty]), [sort_index], [sort_order], [by_col])
PartWhat it doesExample
arrayThe data to return, without headersA2:D8
includeA TRUE/FALSE test for each rowB2:B8="North"
if_emptyWhat to show if nothing matches (optional)"No matches"
sort_indexWhich column of the result to sort by4
sort_order1 for smallest first, -1 for largest first-1

Both functions are dynamic array functions: the result spills, which means it fills as many cells as it needs, starting from the cell with the formula. They need Excel 2021 or Microsoft 365. The FILTER function guide and the SORT function guide cover each argument in detail.

All the examples use this sales list in A1:D8:

ABCD
1RepRegionProductSales
2AnaNorthLaptop4,200
3BenSouthMonitor1,800
4ChenNorthMonitor2,600
5DevEastLaptop5,100
6EllaNorthLaptop3,900
7FemiSouthLaptop4,700
8GusNorthMonitor1,500

Filter one region and sort by sales#

Click F2 and type:

Excel formula
=SORT(FILTER(A2:D8,B2:B8="North"),4,-1)

FILTER keeps the four North rows. SORT then orders them by the 4th column, Sales, with -1 for largest first. The result fills F2:I5:

RepRegionProductSales
AnaNorthLaptop4,200
EllaNorthLaptop3,900
ChenNorthMonitor2,600
GusNorthMonitor1,500

The headers are not part of the result. Type or copy them into row 1 above the formula. If you change Chen's sales to 5,000, he moves to the top straight away. For more on the inner part, see the complete guide to the FILTER function.

Why FILTER goes inside SORT#

You could also write SORT inside FILTER, but filtering first is usually better. There are two reasons:

  1. SORT has less work to do. It only orders the rows that passed the filter.
  2. The column number is simpler. sort_index counts the columns of whatever SORT receives. Here FILTER returns all four columns, so Sales is column 4. If FILTER returned only columns B to D, Sales would be column 3.

That second point is the most common mistake. The number is a position in the result, not a column letter on the sheet.

Add more conditions: AND and OR#

FILTER handles several conditions with simple maths on the TRUE/FALSE tests. Put each test in brackets.

AND (both must be true): multiply. North laptops, largest first:

Excel formula
=SORT(FILTER(A2:D8,(B2:B8="North")*(C2:C8="Laptop")),4,-1)

The result is Ana (4,200) then Ella (3,900).

OR (either can be true): add. North or South, largest first:

Excel formula
=SORT(FILTER(A2:D8,(B2:B8="North")+(B2:B8="South")),4,-1)

This returns six rows, starting with Femi (4,700) and Ana (4,200). The guide to FILTER with multiple criteria covers longer combinations, and you can also filter by part of a word, as shown in FILTER rows that contain text.

To make the formula easy to reuse, point the condition at a cell. If G1 holds a region name, B2:B8=G1 filters by whatever you type there.

Sort by two columns#

Give SORT a list of columns and a list of orders, in curly brackets. This takes the laptop rows, then sorts by Region A to Z, then by Sales largest first within each region:

Excel formula
=SORT(FILTER(A2:D8,C2:C8="Laptop"),{2,4},{1,-1})
RepRegionProductSales
DevEastLaptop5,100
AnaNorthLaptop4,200
EllaNorthLaptop3,900
FemiSouthLaptop4,700

Ana comes before Ella because they are both North, and her sales are higher.

To sort by a column you don't want to show, use SORTBY instead of SORT. SORTBY sorts by a separate range of the same height. In Microsoft 365, you can also trim the result to certain columns with CHOOSECOLS: =CHOOSECOLS(SORT(FILTER(A2:D8,B2:B8="North"),4,-1),1,4) returns only Rep and Sales.

Return the top N matching rows#

A sorted, filtered list makes a natural top N report. In Microsoft 365, wrap it in TAKE to keep only the first rows:

Excel formula
=TAKE(SORT(FILTER(A2:D8,C2:C8="Laptop"),4,-1),2)

This returns the top two laptop sales: Dev (5,100) and Femi (4,700). TAKE is newer than SORT and FILTER, so it isn't in Excel 2021. There, use INDEX(...,SEQUENCE(2),SEQUENCE(1,4)) around the same formula to pick the first two rows.

To add up the filtered values instead of listing them, see how to filter and sum with one formula. To keep rows within a date range, see filtering by date.

Common errors and how to fix them#

Most problems with a sort and filter formula come from five causes:

ErrorCauseFix
#CALC!No rows match the conditionAdd if_empty: FILTER(A2:D8,B2:B8="West","No matches")
#SPILL!Cells where the result needs to go are not emptyClear the cells below and to the right
#VALUE!The include range is a different height from the data, or sort_index is bigger than the number of columnsMake both ranges cover rows 2 to 8, and count the result's columns
#NAME?Excel 2019 or older, or a typo in the function nameUse Excel 2021 or Microsoft 365, or the Sort and Filter buttons
Wrong ordersort_index points at the wrong columnCount columns in the FILTER result, not on the sheet

If you add new rows below the data, a fixed range like A2:D8 won't include them. Turn the data into an Excel table with Ctrl+T (Mac: ⌘T) and use the table's column names, so the ranges grow by themselves.

Practise it#

This formula is a favourite in modern Excel tests because it shows you understand spilled results. Try the exercise on this page first. Then practise SORT in a live spreadsheet: you type the formula and it checks it instantly. Follow it with the FILTER function lesson to build conditions with AND and OR.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

In F2, write one formula that returns the North rows only, sorted by Sales (column 4 of the data) from largest to smallest.

fx
ABCDEFG
1
Rep
Region
Product
Sales
2
Ana
North
Laptop
4200
3
Ben
South
Monitor
1800
4
Chen
North
Monitor
2600
5
Dev
East
Laptop
5100
6
Ella
North
Laptop
3900
7
Femi
South
Laptop
4700
8
Gus
North
Monitor
1500
9
10
11

Tip: Start with FILTER(A2:D8,B2:B8="North"), then wrap it in SORT with 4 for the Sales column and -1 for largest first.

Practise this in a lesson

LessonSORT: order data with a formulaSort a table by any column, ascending or descending, and combine SORT with FILTER and UNIQUE.LessonFILTER: pull matching rows with a formulaReturn every row that meets one or more conditions with FILTER, and show a friendly message when nothing matches.Function guideSORTSort a range with a formula using Excel's SORT. Sort by any column, highest first, or combined with FILTER. Includes a live exercise.Function guideFILTERReturn every row that matches a condition with Excel's FILTER. Multiple criteria, empty results and #SPILL! explained, with live practice.

Frequently asked questions

Can you sort and filter at the same time in Excel?

+

Yes. In Excel 2021 or Microsoft 365, nest FILTER inside SORT, for example =SORT(FILTER(A2:D8,B2:B8="North"),4,-1). The result is a filtered list that is already sorted and updates by itself.

Should SORT go inside FILTER or FILTER inside SORT?

+

Usually FILTER goes inside SORT. Filtering first means SORT has fewer rows to order, and the sort column number refers to the columns FILTER returns. Both orders give the same rows.

How do I sort a filtered list by two columns?

+

Give SORT arrays of column numbers and orders: =SORT(FILTER(A2:D8,C2:C8="Laptop"),{2,4},{1,-1}) sorts by column 2 A to Z, then by column 4 largest first.

Why does SORT FILTER return #CALC!?

+

No rows match the condition, so FILTER has nothing to return. Add the third FILTER argument, for example "No matches", to show a message instead.

Does SORT FILTER work in Excel 2016 or 2019?

+

No. Both functions need Excel 2021 or Microsoft 365. In older versions, use AutoFilter and the Sort button on the Data tab instead.

Sources

  • SORT function - Microsoft Support
  • FILTER function - Microsoft Support
  • Dynamic array formulas and spilled array behavior - Microsoft Support

Written and checked by the ExcelReady Team. First published November 2, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. The sort and filter formula pattern
  2. Filter one region and sort by sales
  3. Why FILTER goes inside SORT
  4. Add more conditions: AND and OR
  5. Sort by two columns
  6. Return the top N matching rows
  7. Common errors and how to fix them
  8. Practise it

Keep reading

Dynamic arrays· 6 min read

Sum, Count or Average FILTER Results in Excel

To sum FILTER results in Excel, put FILTER inside SUM: =SUM(FILTER(D2:D9,B2:B9="East")) adds the sales of East rows only. Swap SUM for COUNT, AVERAGE or MAX for other answers. Add 0 as FILTER's third argument so no matches return 0 instead of #CALC!. To total rows left visible by the filter buttons, use =SUBTOTAL(109,D2:D9).

Dynamic arrays· 6 min read

FILTER by Date in Excel: Month, Range or Recent

To filter by date in Excel with a formula, give FILTER two date tests multiplied together. For March 2024: =FILTER(A2:C9,(A2:A9>=DATE(2024,3,1))*(A2:A9<=DATE(2024,3,31))). Put the start and end dates in cells to change the range without editing the formula. For recent rows, use A2:A9>=TODAY()-30. FILTER needs Excel 2021, Excel 2024 or Microsoft 365.

Dynamic arrays· 6 min read

FILTER Rows That Contain Text in Excel

To filter rows that contain text in Excel, combine FILTER with ISNUMBER and SEARCH: =FILTER(A2:C8,ISNUMBER(SEARCH("desk",A2:A8))). SEARCH returns a position where the text is found and an error where it isn't, and ISNUMBER turns that into TRUE or FALSE for each row. Use FIND instead of SEARCH for a case-sensitive match. FILTER needs Excel 2021 or Microsoft 365.

More on dynamic arrays

  • Sort by Multiple Columns in Excel (Formula and Menu)
  • Sort by a Custom Order With a Formula
  • SORT and SORTBY in Excel
  • #SPILL! Error in Excel: What It Means and How to Fix It
  • The Spill Range Operator (#) in Excel
  • TAKE Function in Excel (and DROP): First or Last N Rows
All dynamic arrays articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free