SORT takes the range to sort, the column index to sort by, and the direction: 1 for ascending, -1 for descending. When the sort index is left out, SORT sorts by the first column, which an AI assistant may not have intended when the table’s key column sits elsewhere. Read the sort index and direction before trusting the order.
What you need
- The AI-written SORT formula
- The table it sorts, with its columns labelled
- The order the reader expects to see
Step 1: Read the sort index and direction
Click the formula cell and read the second and third arguments. The sort index is the column number inside the sorted range, counting from 1, and the direction is 1 for ascending or -1 for descending.
Step 2: Check the first and last rows of the result
Read the first and last rows of the sorted output and check them against the source. The first row should hold the smallest or largest value of the intended column, depending on the direction.
Step 3: Fix the index and re-check
Set the sort index to the intended column and the direction to match the question, then re-check the first and last rows. If the result still looks wrong, check that the sorted range includes the column you meant.
Worked example: synthetic product sales table
The table below is a synthetic example. It shows the expected result of checking an AI-written SORT formula; no formula was run.
| Check | Value | Result |
|---|---|---|
| Sort index as written | 1 | Sorts by product name |
| First row returned | Apples | Alphabetical, not by sales |
| Corrected sort index | 2 | Sorts by the sales column |
| First row after fix | Bananas, 220 | Highest sales first |
Expected result (UNTESTED). the SORT formula with sort index 1 returns Apples first, sorted by name; changing the index to 2 returns Bananas with 220 first, the highest sales. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- The sort index counts columns inside the sorted range, not columns on the sheet, so a range starting at column B shifts every index by one.
- SORT is a dynamic array function, so a blocked cell in the spill range stops it with #SPILL!.
- Sorting text with numbers mixed in puts the numbers first, which can look like a wrong order.
- SORT does not change the source data; it returns a sorted copy, so the original order stays where it was.
