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.
Inside Dynamic_Reports, confirm the following inputs exist:
| Cell | Value |
|---|---|
| J2 | North |
| J4 | 3000 |
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.
Review the output and confirm that rows are grouped alphabetically by region.
Within each group, verify that Revenue values appear from highest to lowest.
All FILTER conditions inside SORTBY must return arrays with identical row counts.
If one array becomes misaligned, the formula fails.
Inside a separate cell, type:
=LARGE(Sales_Data!H2:H52, 1)
This returns the highest Revenue value in the dataset.
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.
Change the region value inside J2.
Notice that:
- The
SORTBYreport updates automatically; - The
LARGEKPI 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?
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat