Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Advanced Sorting with SORTBY and LARGE | Dynamic Arrays and Interactive Reporting
Excel Formulas

Advanced Sorting with SORTBY and LARGE

Swipe to show menu

SORT works well for basic ranking, but more advanced reports often require multiple sorting layers or independent sorting references. In this chapter, use SORTBY for multi-level ranking and LARGE for KPI extraction.

SORTBY Structure

=SORTBY(array, by_array1, sort_order1, [by_array2, sort_order2])
  • array: dataset being returned;
  • by_array1: first sorting reference;
  • sort_order1: first sorting direction;
  • by_array2: optional second sorting reference;
  • sort_order2: second sorting direction.

Unlike SORT, SORTBY uses external arrays instead of internal column positions.

LARGE Structure

=LARGE(array, k)
  • array: numeric values being evaluated;
  • k: ranking position;
  • 1: largest value;
  • 2: second-largest value.

LARGE returns a single ranked value instead of a full sorted dataset.

Step 1 Confirm Input Values
expand arrow

Inside Dynamic_Reports, confirm the following inputs exist:

CellValue
J2North
J43000
Step 2 Build the SORTBY Report
expand arrow

Replace the previous SORT formula with:

=SORTBY(
FILTER(Sales_Data!A2:H52,(Sales_Data!E2:E52=J2)*(Sales_Data!H2:H52>J4),"No results found"),
FILTER(Sales_Data!E2:E52,(Sales_Data!E2:E52=J2)*(Sales_Data!H2:H52>J4),"No results found"),1,
FILTER(Sales_Data!H2:H52,(Sales_Data!E2:E52=J2)*(Sales_Data!H2:H52>J4),"No results found"),-1
)
  • First sorting layer: Region ascending;
  • Second sorting layer: Revenue descending.
Step 3 Test Primary Sorting
expand arrow

Review the output and confirm that rows are grouped alphabetically by region.

Step 4 Test Secondary Ranking
expand arrow

Within each group, verify that Revenue values appear from highest to lowest.

Step 5 Validate Array Consistency
expand arrow

All FILTER conditions inside SORTBY must return arrays with identical row counts. If one array becomes misaligned, the formula fails.

Step 6 Extract the Highest Revenue Value
expand arrow

Inside a separate cell, type:

=LARGE(Sales_Data!H2:H52, 1)

This returns the highest Revenue value in the dataset.

Step 7 Add Dynamic Filtering to LARGE
expand arrow

Replace the formula with:

=LARGE(FILTER(Sales_Data!H2:H52, Sales_Data!E2:E52=J2), 1)
  • FILTER(...): restricts the dataset to the selected region;
  • 1: returns the highest Revenue value.
Step 8 Test Dynamic KPI Updates
expand arrow

Change the region value inside J2. Notice that:

  • The SORTBY report updates automatically;
  • The LARGE KPI updates automatically.

1. Why does SORTBY allow more flexibility than SORT?

2. What is a strict requirement for arrays used inside SORTBY?

3. What is the main difference between SORT/SORTBY and LARGE?

question mark

Why does SORTBY allow more flexibility than SORT?

Select the correct answer

question mark

What is a strict requirement for arrays used inside SORTBY?

Select the correct answer

question mark

What is the main difference between SORT/SORTBY and LARGE?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 4

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Section 2. Chapter 4
some-alt