New Tool Radar

AI for Data & Spreadsheets

How to Check Whether an AI-Written LARGE or SMALL Formula Returns the Intended Top Values

Check whether an AI-written LARGE or SMALL formula returns the intended top-N values, including ties.

Schematic with three steps: Sort a copy of the range by; Check the n in each LARGE or; Compare the formula's list with the hand-sorted.

LARGE returns the nth largest value in a range and SMALL the nth smallest, which makes them the direct way to list a top three without sorting. An AI-written formula can ask for the wrong n, or ignore ties: when two values tie for second place, LARGE with n of 2 and 3 returns the same value twice, and a top-three list shows a duplicate instead of the next distinct value. Check the n and the ties before publishing the list.

What you need

  • The AI-written LARGE or SMALL formula
  • The range it reads, sorted by hand
  • The top values the reader expects to see

Step 1: Sort a copy of the range by hand

Sort a copy of the values from largest to smallest and write down the top three, including any ties. This is the list the formula should return.

Step 2: Check the n in each LARGE or SMALL call

Read the second argument of each call: LARGE(range,1) is the largest, LARGE(range,2) the second largest, and so on. A list that repeats the same n returns the same value twice.

Step 3: Compare the formula’s list with the hand-sorted list

Run the formula and compare its values with the hand-sorted list, position by position. If a tie duplicates a value, say so in the report or use UNIQUE to list distinct values.

Worked example: synthetic sales figures with a tie

The table below is a synthetic example. It shows the expected result of checking an AI-written LARGE formula; no formula was run.

Check Value Result
Values in the range 500, 400, 400, 300 Four sales figures
LARGE 1, 2, 3 500, 400, 400 Second place ties
Top three distinct values 500, 400, 300 What the reader expects
List after fix 500, 400, 300 Uses UNIQUE on the top values

Expected result (UNTESTED). LARGE with n of 1, 2 and 3 returns 500, 400 and 400, because two values tie for second place; the reader’s top-three distinct list is 500, 400 and 300. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • LARGE and SMALL return values, not the rows those values sit on; use INDEX and MATCH to find the row.
  • A tie makes LARGE return the same value for two different n, so a top-N list can repeat a value.
  • LARGE with an n larger than the count of numbers returns #NUM!.
  • Text and blank cells in the range are ignored by LARGE and SMALL, which can shift the ranking.

Sources

See all