Skip to main content
ExcelFILTER with SORT and CHOOSECOLSLookup & ReferenceCombo RecipeArrayExcel 365Data AnalysisDynamic Arrays

The Problem

Are you drowning in vast spreadsheets, constantly battling to extract just the right sliver of information? Perhaps you've spent countless hours manually filtering, then copying, then pasting, and finally sorting specific columns from a massive dataset. It's a familiar, frustrating dance: you need sales figures for a particular region, but only the Sales Rep, Date, and Revenue columns, and then you need them sorted by revenue, highest to lowest. What is FILTER with SORT and CHOOSECOLS? This powerful combination is an Excel dynamic array recipe that allows you to efficiently perform all these operations in a single, elegant formula. It's commonly used to transform raw data into actionable insights without altering the original source.

The traditional approach involves multiple manual steps, each prone to human error and consuming precious time. You might use the standard Data Filter, then manually hide columns, then copy visible cells, and finally paste them elsewhere. This process becomes a nightmare when your source data updates, forcing you to repeat every step. What if you could write one formula that dynamically adjusts to changes, always presenting precisely what you need, exactly how you need it?

Business Context & Real-World Use Case

Imagine you're a Business Analyst for a growing retail company. Every day, you receive raw sales transaction data – thousands, sometimes hundreds of thousands, of rows detailing every sale across multiple regions, products, and sales representatives. Your manager asks for a weekly report: "Show me the top revenue-generating sales in our North region from last week, but I only need the Sales Rep, the Transaction Date, and the Revenue amount. Oh, and make sure the highest revenue is at the top."

Doing this manually every week is not just inefficient; it's a huge operational risk. In my years as a data analyst, I've seen teams waste hours on repetitive tasks like this, leading to delayed reports, missed deadlines, and even errors creeping in due to fatigue or oversight. Automating this with FILTER with SORT and CHOOSECOLS transforms a laborious, error-prone task into a click-of-a-button solution. It provides instantaneous, accurate insights, freeing up analysts to focus on higher-value activities like interpretation and strategy. This formula isn't just about saving time; it's about ensuring data integrity and empowering quicker, more informed business decisions.

The Ingredients: Understanding FILTER with SORT and CHOOSECOLS's Setup

The magic of FILTER with SORT and CHOOSECOLS lies in chaining these powerful Excel 365 dynamic array functions together. Each function plays a crucial role, working in sequence to achieve our desired result: filtering, then sorting the filtered output, and finally selecting specific columns from that sorted output. The general structure of our combined formula will look like this:

=CHOOSECOLS(SORT(FILTER(array, include, [if_empty]), sort_col, [sort_order], [by_row]), col_num1, [col_num2], ...)

Let's break down each 'ingredient' in this powerful recipe:

1. FILTER Function
Its job is to reduce your dataset to only the rows that meet your specified criteria.
FILTER(array, include, [if_empty])

Parameter Description
array The range or array of data you want to filter. This is your entire raw dataset.
include A Boolean array (TRUE/FALSE) specifying which rows to include. This is where you define your filtering conditions (e.g., Table1[Region]="North").
[if_empty] (Optional) The value to return if no rows satisfy the include condition. If omitted, FILTER returns a #CALC! error. A professional best practice is to always specify a user-friendly message like "No Data".

2. SORT Function
This function takes the array produced by FILTER and arranges its rows based on one or more columns in a specified order.
SORT(array, sort_index, [sort_order], [by_row])

Parameter Description
array The range or array you want to sort. In our combo, this will be the output from the FILTER function.
sort_index The column number (1-based index) within the array that you want to sort by. If array is a table, this is the column number within that table's range, not necessarily the worksheet column number.
[sort_order] (Optional) Specifies the sort order. 1 for ascending (default), -1 for descending.
[by_row] (Optional) A logical value specifying how to sort. TRUE to sort by row (columns will move), FALSE to sort by column (rows will move). For typical tabular data sorting, this is usually FALSE or omitted (default sort by column, affecting rows).

3. CHOOSECOLS Function
The final step, this function lets you pick precisely which columns you want from the array produced by SORT, discarding the rest.
CHOOSECOLS(array, col_num1, [col_num2], ...)

Parameter Description
array The array from which you want to return columns. In our case, this is the output of the SORT function.
col_num1, ... The 1-based index or indices of the columns you want to return from the array. These refer to the columns within the array passed to CHOOSECOLS, not the original worksheet columns. Can be positive or negative (from right).

The Recipe: Step-by-Step Instructions

Let's dive into a practical example. We have a sales dataset named SalesData (a formatted Excel Table, which is a professional best practice for robust formulas). Our goal is to extract sales from the "North" region, showing only the "Sales Rep", "Date", and "Revenue" columns, sorted by "Revenue" in descending order.

Sample Data (Table named SalesData):

Region Sales Rep Date Product Revenue
East Alice 2023-01-10 Laptop 1200
North Bob 2023-01-12 Mouse 75
West Carol 2023-01-11 Keyboard 120
North David 2023-01-15 Monitor 300
South Emily 2023-01-13 Webcam 50
North Bob 2023-01-18 Desk Lamp 45
East Frank 2023-01-14 Tablet 600
North David 2023-01-16 Projector 800
West Grace 2023-01-17 Microphone 90
North Sarah 2023-01-19 VR Headset 1500

Assume this SalesData table occupies cells A1:E11 on your worksheet, with headers in row 1.

Here’s how we construct the formula:

  1. Select Your Cell: Click on the cell where you want the filtered, sorted, and extracted data to begin (e.g., cell G2).

  2. Start with FILTER: First, we filter the SalesData table to include only rows where the Region column is "North".

    • Type: =FILTER(SalesData, SalesData[Region]="North", "No North Region Sales")
    • Explanation: This will return a dynamic array containing all columns (Region, Sales Rep, Date, Product, Revenue) for rows where Region is "North". If no "North" sales are found, it will display "No North Region Sales".

    Partial Result (in memory, not yet displayed):

    Region Sales Rep Date Product Revenue
    North Bob 2023-01-12 Mouse 75
    North David 2023-01-15 Monitor 300
    North Bob 2023-01-18 Desk Lamp 45
    North David 2023-01-16 Projector 800
    North Sarah 2023-01-19 VR Headset 1500
  3. Nest with SORT: Next, we take the output from our FILTER function and sort it. We want to sort by the Revenue column in descending order. In our SalesData table, Revenue is the 5th column.

    • Modify the formula to: =SORT(FILTER(SalesData, SalesData[Region]="North", "No North Region Sales"), 5, -1)
    • Explanation: The 5 indicates the 5th column of the filtered array (which is the Revenue column), and -1 specifies descending order.

    Partial Result (in memory, sorted):

    Region Sales Rep Date Product Revenue
    North Sarah 2023-01-19 VR Headset 1500
    North David 2023-01-16 Projector 800
    North David 2023-01-15 Monitor 300
    North Bob 2023-01-12 Mouse 75
    North Bob 2023-01-18 Desk Lamp 45
  4. Enclose with CHOOSECOLS: Finally, we'll select only the "Sales Rep", "Date", and "Revenue" columns from the sorted, filtered data. Looking at our SalesData table structure, these correspond to columns 2, 3, and 5, respectively.

    • Complete the formula: =CHOOSECOLS(SORT(FILTER(SalesData, SalesData[Region]="North", "No North Region Sales"), 5, -1), 2, 3, 5)
    • Explanation: The 2, 3, 5 tell CHOOSECOLS to extract the 2nd, 3rd, and 5th columns from the array generated by SORT(FILTER(...)).

Final Working Formula:

=CHOOSECOLS(SORT(FILTER(SalesData, SalesData[Region]="North", "No North Region Sales"), 5, -1), 2, 3, 5)

The Result:
Upon entering this formula in cell G2, Excel will spill the following dynamic array, neatly presenting exactly what was requested:

Sales Rep Date Revenue
Sarah 2023-01-19 1500
David 2023-01-16 800
David 2023-01-15 300
Bob 2023-01-12 75
Bob 2023-01-18 45

This single formula has transformed your raw data, filtered it, sorted it, and extracted the precise columns you needed, all dynamically updating if the SalesData table changes.

Pro Tips: Level Up Your Skills

  1. Use Excel Tables: As an Excel consultant, I always recommend converting your raw data into an Excel Table (Insert > Table). This makes your formulas incredibly robust, using structured references like SalesData[Region] instead of A:A. It automatically expands as you add new data, ensuring your FILTER with SORT and CHOOSECOLS formula always references the full dataset.
  2. Externalize Criteria: Instead of hardcoding "North" into your FILTER condition, put it in a separate cell (e.g., B1). Then reference that cell: SalesData[Region]=B1. This makes your formula far more flexible; you only need to change the value in B1 to instantly update your report for a different region.
  3. Define Named Ranges for Column Indices: For complex tables, remembering that Revenue is column 5 or Sales Rep is 2 can be tedious and error-prone. Consider using XMATCH to dynamically find column indices: XMATCH("Revenue", SalesData[#Headers]). This makes your SORT and CHOOSECOLS parameters resilient to column reordering in your source data. For example:
    =CHOOSECOLS(SORT(FILTER(SalesData, SalesData[Region]="North", "No North Region Sales"), XMATCH("Revenue", SalesData[#Headers]), -1), XMATCH("Sales Rep", SalesData[#Headers]), XMATCH("Date", SalesData[#Headers]), XMATCH("Revenue", SalesData[#Headers]))
    While longer, this formula is far more adaptable in a dynamic data environment.

Troubleshooting: Common Errors & Fixes

Even expert chefs occasionally burn the toast. When working with dynamic array functions like FILTER with SORT and CHOOSECOLS, specific errors can pop up. Understanding their symptoms, causes, and fixes is crucial.

1. #CALC! Error

  • Symptom: Your formula returns #CALC!. Sometimes accompanied by a message like "Empty array."
  • Cause: This usually occurs when the FILTER function's include criteria do not match any rows in the array, and you have not provided the optional [if_empty] argument. It means your filter condition returned no data. A common mistake we've seen is subtle typos in the filter criteria (e.g., "Nort" instead of "North").
  • Step-by-Step Fix:
    1. Check Filter Criteria: Double-check the spelling and casing of your filter condition (e.g., "North"). Ensure it exactly matches values in your SalesData[Region] column. Excel functions are case-sensitive by default for text comparisons unless you use functions like EXACT or manipulate strings.
    2. Add [if_empty] Argument: The easiest fix and a professional best practice is to always include the [if_empty] argument in your FILTER function. This provides a user-friendly message instead of an error. For instance, change FILTER(SalesData, SalesData[Region]="North") to FILTER(SalesData, SalesData[Region]="North", "No matching data found").
    3. Verify Data Type: Ensure the data type in your include column matches your criteria. If SalesData[Region] contains numbers formatted as text, and you're searching for 123, it might not match.

2. #VALUE! Error

  • Symptom: Your formula returns #VALUE!.
  • Cause: This error often arises when the sort_index or col_num arguments in SORT or CHOOSECOLS are invalid (e.g., non-numeric, a text string, or out of range). It can also occur if the sort_order in SORT is anything other than 1 or -1.
  • Step-by-Step Fix:
    1. Inspect Column Indices: Verify that the sort_index in SORT (e.g., 5) and the col_num arguments in CHOOSECOLS (e.g., 2, 3, 5) are all valid, positive integers representing actual columns within the array being passed to them. If your original data has 5 columns, you cannot reference column 6.
    2. Check Sort Order: Ensure the sort_order parameter in SORT is either 1 (for ascending) or -1 (for descending). Any other number or text will cause a #VALUE! error.
    3. Data Type Consistency: If your sort_index column contains mixed data types (e.g., numbers and text), SORT might struggle, leading to unexpected results or errors in some Excel versions, although it's more likely to sort text numerically or vice-versa rather than a hard error.

3. Incorrect Results / Unexpected Output

  • Symptom: The formula completes without an error, but the data is not what you expected (e.g., wrong columns, incorrect sort order, or missing rows).
  • Cause: This typically points to logical errors in your arguments, especially with the include condition in FILTER, or incorrect column indexing in SORT or CHOOSECOLS. Perhaps the filter condition is too broad or too narrow, or you're sorting by the wrong column.
  • Step-by-Step Fix:
    1. Deconstruct the Formula: Experienced Excel users know that the best way to debug complex nested formulas is to break them down.
      • First, enter just the FILTER part of your formula in a cell (=FILTER(SalesData, SalesData[Region]="North", "No Data")) and examine its output. Does it show the correct rows?
      • Next, wrap that FILTER output with SORT (=SORT(FILTER(SalesData, ...), 5, -1)). Does this correctly sort the data?
      • Finally, add CHOOSECOLS. By examining each step's output, you can pinpoint exactly where the logic diverges from your expectation.
    2. Verify Column Indices Carefully: Pay close attention to the column numbers you're providing to SORT and CHOOSECOLS. These refer to the relative position of columns within the array being processed, not necessarily their original worksheet column letters. For example, if SalesData has 5 columns, and Revenue is the 5th column, then SORT uses 5. If CHOOSECOLS is picking columns 2, 3, and 5, it means the 2nd, 3rd, and 5th columns from the output of the SORT function.
    3. Review Filter Logic: If your FILTER condition uses multiple criteria (e.g., (SalesData[Region]="North")*(SalesData[Revenue]>100) for AND, or (SalesData[Region]="North")+(SalesData[Revenue]>100) for OR), ensure your Boolean logic is correctly constructed.

Quick Reference

Feature Description
Syntax =CHOOSECOLS(SORT(FILTER(array, include, [if_empty]), sort_index, [sort_order]), col_num1, [col_num2], ...)
Common Use Dynamically extracting specific, filtered, and sorted columns from a large dataset, ideal for creating reports, dashboards, or subsets of data without modifying the source. Perfect for Excel 365 users.
Best Practice Always use Excel Tables for your source data, externalize filter criteria, and consider XMATCH for dynamic column indexing to create highly robust and adaptable formulas.
Key Errors #CALC! (filter returns empty), #VALUE! (invalid sort/column index or order), Incorrect results (logical errors in criteria or column indexing).

Related Functions

👨‍💻

Written by The Head Chef

Former 10-year Financial Analyst who survived countless month-end closes. I build these recipes to save you from weekend-ruining spreadsheet errors.

Read the full story →

You might also find these useful 💡