Sort by Field Labels Using the SORT and XMATCH Combo in Excel

Want to sort your Excel data by column names instead of column positions? Learn how to dynamically sort by field labels in Excel using the powerful SORT and XMATCH combo in Excel—no more manual lookups or helper columns! This guide walks you through practical examples, from static field label sorting to fully dynamic dropdown-based sorting.

Why Use the SORT and XMATCH Combo in Excel?

This approach is helpful in several scenarios:

  • You don’t need to manually determine the column index to sort.
  • It sticks to the correct column even if you move it within the table.
  • You can dynamically control the sort column(s) using drop-down lists.
Note: The formula works in Excel versions that support the XMATCH and SORT functions, as well as dynamic arrays (Excel 365 and Excel 2021 and later).

Examples: Sort by Field Labels in Excel

The SORT and XMATCH combo in Excel varies slightly depending on whether you want to sort by a single field label or multiple field labels.

Sample Data (A1:C5):

NameDepartmentSales
SamuelHR5000
JuliaFinance7000
PrashanthIT6500
AmaliaHR4800

1. Sort by a Single Field Label

To sort by the field label “Department”, use this formula:

=SORT(A2:C5, XMATCH("Department", A1:C1), 1)
  • A2:C5 is the range to sort (array).
  • XMATCH("Department", A1:C1) returns the column index of the field label.
  • 1 indicates ascending sort order.
Example of using the SORT and XMATCH combo in Excel

This aligns with the syntax:

SORT(array, [sort_index], [sort_order], [by_col])

2. Sort by Multiple Field Labels

To sort by both Department and Sales, use:

=SORT(A2:C5, XMATCH({"Department","Sales"}, A1:C1), {1,1})
  • You pass an array of field labels: {"Department","Sales"}.
  • You also pass a corresponding array for sort order: {1,1} (ascending).

This ensures that sorting happens by Department first, then by Sales.

Sort by Field Label Selected via Drop-down List

To make sorting more interactive, use drop-downs to let users select the sort field(s).

Example: Sort by One Drop-down Selection

  1. Create a drop-down in cell E1:
    • Go to the Data tab → Data Validation.
    • Choose List.
    • Set the Source to: =A1:C1 (or manually type Name,Department,Sales).
  2. Select “Department” from the drop-down.
  3. Use this formula:
=SORT(A2:C5, XMATCH(E1, A1:C1), 1)
Sort data by field label selected from a drop-down list in Excel

Example: Sort by Two Drop-downs

  1. Add another drop-down in cell E2.
  2. Select “Sales” in cell E2.
  3. Use this formula:
=SORT(A2:C5, XMATCH(E1:E2, A1:C1), {1,1})

This enables dynamic multi-column sorting based on user selection.

Frequently Asked Questions

Q: Can I use SORT and XMATCH in older versions of Excel?
A: No, these functions require Excel 365 or Excel 2021+ with support for dynamic arrays.

Q: How is XMATCH better than MATCH?
A: XMATCH offers more flexibility, including exact match by default, reverse search, and support for arrays—making it ideal for modern Excel functions like SORT.

Resources

By using the SORT and XMATCH combo in Excel, you can efficiently sort by field labels in Excel—making your spreadsheets more dynamic and user-friendly.

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Custom Order for QUERY Pivot Headers in Google Sheets

By default, when you use the PIVOT clause in a Google Sheets QUERY, the...

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

Mode of Comma-Separated Numbers in Excel (Dynamic Array)

There is no dedicated function in Excel to directly find the mode of comma-separated...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

More like this

Mode of Comma-Separated Numbers in Excel (Dynamic Array)

There is no dedicated function in Excel to directly find the mode of comma-separated...

Sort Each Row Individually in Excel Using a LAMBDA Formula

Sorting rows in Excel typically refers to rearranging entire datasets based on values in...

Dynamic Way to Insert Blank Rows in a Table in Excel

Do you want to easily insert n number of blank rows in a table...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.