Ravindra BagaleCourses & study guides मराठी Track your progress

9. Dynamic Arrays

9.3 SORT and SORTBY

SORT by a column with example — in 30 seconds

What: SORT returns a sorted copy of a range. The original data stays as it is.

Why: A "biggest orders first" list on a report sheet stays sorted even after new rows arrive.

Tiny example: =SORT(tblMini, 7, -1) sorts by the 7th column (Amount), biggest first. ₹1,299 comes to the top.

First look at the data (before → after):

SORT by a column with example: before and after tables, fictional FreshGo Maharashtra data

Expected result — Spilled result (selected columns)

Order ID City Amount
BLK-1007 Solapur 1299
BLK-1002 Nashik 270
BLK-1004 Nagpur 240
AMN-1005 Kolhapur 232
BLK-1009 Pune 220
AMN-1008 Sambhaji Nagar 195
BLK-1006 Pune 150
AMN-1003 Pune 110
BLK-1010 Nashik 90
BLK-1001 Pune 64

About this data: Teaching sample for a fictional shop “QuickCart Delivery”. Figures and names (e.g. Aarti Kulkarni) are made up for this lesson on sort and sortby.

Before table and formula as text

Before — tblMini in entry order

Order ID City Amount
BLK-1001 Pune 64
BLK-1002 Nashik 270
AMN-1003 Pune 110
BLK-1004 Nagpur 240
AMN-1005 Kolhapur 232
BLK-1006 Pune 150
BLK-1007 Solapur 1299
AMN-1008 Sambhaji Nagar 195
BLK-1009 Pune 220
BLK-1010 Nashik 90

About this data: Demo table only — not real customer or company data. Built to practise sort and sortby.

Formula / click path

K2: =SORT(tblMini, 7, -1)
7 = Amount is the 7th column · -1 = descending

Do it step by step:

  1. Click an empty cell such as K2.
  2. Type =SORT(tblMini, 7, -1).
  3. Press Enter. All ten rows spill, biggest amount first.
  4. For City A to Z, then Amount high to low, use =SORTBY(tblMini, tblMini[City], 1, tblMini[Amount], -1).
  5. Check the top row is BLK-1007.
  • =SORT(array, [sort_index], [sort_order], [by_col]) – sort by a column number inside the array; order 1 = ascending, -1 = descending.
  • =SORTBY(array, by_array1, [sort_order1], [by_array2, sort_order2], …) – sort by any array, even one not shown.
Need Formula
Orders by Amount, largest first =SORT(tblMini, 7, -1)
By City A–Z, then Amount high–low =SORTBY(tblMini, tblMini[City], 1, tblMini[Amount], -1)
Order IDs sorted by delivery time (show only IDs) =SORTBY(tblMini[Order ID], tblMini[Mins], 1)
Pune orders sorted =SORT(FILTER(tblMini, tblMini[City]="Pune"), 7, -1)

About this data: Made-up rows so you can copy the pattern for sort and sortby. Currencies may use ₹, £, € or $.

Worked example. =SORTBY(tblMini[Order ID], tblMini[Mins], 1) starts with BLK-1006 (8 mins), BLK-1001 (9), AMN-1008 (10)…

Ravindra Bagale's Tip

In SORT, sort_index is the column number within the array, not on the sheet. If you apply SORT to 3 FILTERed columns, Amount will be column 3, not 7 – many students get #VALUE! here. If in doubt, use SORTBY – it sorts by the column itself.

Practice task

Show all orders sorted by Platform then Amount (high to low). Show Order IDs sorted by delivery time without displaying the time column.

Loading practice tasks...

  1. Courses A to Z (spill) (Easy): Sort A2:A7.
  2. Students low to high (spill) (Easy): Sort C2:C7.
  3. Students high to low (spill) (Easy): Sort C2:C7 big to small.
  4. Courses Z to A (spill) (Easy): Sort A2:A7 Z to A.
  5. Table by students (spill) (Medium): Sort A2:E7 by column 3 (Students), big to small.
  6. Table by rating (spill) (Medium): Sort A2:E7 by column 4, big to small.
  7. Cheapest first (spill) (Medium): Sort A2:E7 by column 5, small to big.
  8. Ratings best first (spill) (Medium): Sort D2:D7 big to small.
  9. Udemy courses, most students first (spill) (Hard): Show only Udemy rows of A2:E7, sorted by column 3 (Students), big to small.
  10. Sorted Udemy courses (spill) (Hard): Show Udemy course names sorted A to Z.
  11. Platforms A to Z, no repeats (spill) (Hard): Sorted list of different platforms.

Quick revision cards

Three standalone cards. Each one explains the idea with its own example. Scan the QR to open this lesson.

Revision card 1: What is Sort And Sortby?
Card 1: What is Sort And Sortby? · Download PNG
Revision card 2: Tiny example — Sort And Sortby
Card 2: Tiny example — Sort And Sortby · Download PNG
Revision card 3: Checklist — Sort And Sortby
Card 3: Checklist — Sort And Sortby · Download PNG