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 Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Sort Each Row Individually in Excel Using a LAMBDA Formula

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

How to Sort Pie Slices in Google Sheets

To sort pie slices in a pie chart, you need to sort the data...

Filter Items Unique to Groups in Google Sheets

In this tutorial, we'll learn how to filter items unique to groups in Google...

Find Common Items Across Multiple Columns in Google Sheets

This tutorial explains how to find common items across multiple columns in Google Sheets....

More like this

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...

Insert N Empty Cells Between Values in Excel (Dynamic Array)

Do you want to space out data by inserting a specific number of empty...

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.