Sort one column by another with a formula
=SORTBY(A2:A9,B2:B9,-1)Excel · result on the sample sheet: 8 rows (D2:D9)
Describe what you need and get a working SORTBY formula for Excel and Google Sheets, tested on real data before you copy it. SORTBY sorts one range by the values in another.
Each formula below was calculated on its own sample sheet. Open one to see the sheet, why it works, and to try it yourself.
=SORTBY(A2:A9,B2:B9,-1)Excel · result on the sample sheet: 8 rows (D2:D9)
=SORTBY(A2:A9,C2:C9,-1)Excel · result on the sample sheet: 8 rows (E2:E9)
=SORTBY(A2:C8,DATEVALUE(A2:A8))Excel · result on the sample sheet: 7 rows (E2:G8)
=SORTBY(A2:C10,XMATCH(B2:B10,F2:F4))Excel · result on the sample sheet: 9 rows (H2:J10)
=SORTBY(A2:B9,MONTH(B2:B9),1,DAY(B2:B9),1)Excel · result on the sample sheet: 8 rows (D2:E9)
=INDEX(SORTBY(A2:A9,B2:B9,-1),E1)Excel · result on the sample sheet: Ben
You describe the task in plain English, and it writes the formula, using SORTBY where that's the right tool, for your table or a sample one. The formula is run in our engine in Excel and Google Sheets mode before you see it, so you get its result, not just a guess.
SORTBY sorts one range by the values in another.
Yes. Each example below opens a page where you try the formula in a live grid and it's checked as you go, and the SORTBY function page has a practice exercise.