Ravindra BagaleCourses & study guides

9. Dynamic Arrays

9.3 SORT and SORTBY

  • =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)

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.