How to Describe a Formula to an AI So It Works the First Time

· 3 min read

Short answer: an AI formula generator cannot see your spreadsheet. It only knows what you tell it. Name the program, say which columns hold what, describe the result you expect, and mention the awkward cases. Those four things remove most wrong answers.

Why vague prompts give wrong formulas

Take this request:

sum sales for january

A correct formula depends on things the request does not say. Where are the sales amounts? Where are the dates, and are they real dates or text such as "Jan"? January of which year? The AI has to guess, and a guess that does not match your sheet gives a formula that returns zero or an error.

Compare it with:

Excel. Dates are in column A, amounts in column C, rows 2 to 500. Sum the amounts for January 2026.

Now there is one sensible answer:

=SUMIFS(C2:C500,A2:A500,">="&DATE(2026,1,1),A2:A500,"<"&DATE(2026,2,1))

Five details to include

1. Excel or Google Sheets, and the version if it is old

The two programs differ in array handling and in a number of functions. Within Excel, functions such as XLOOKUP, FILTER and UNIQUE do not exist before Excel 2021. If you are on Excel 2016 or 2019, say so, or you may get a formula that shows #NAME?.

2. Where the data is

Give column letters and, ideally, the row range: "names in A2:A200, departments in B, salaries in C". "The salary column" forces a guess. If the data is on another sheet, give the sheet name.

3. What the data looks like

Say whether a column holds numbers, dates or text, and mention anything unusual: dates stored as text, numbers with a currency symbol, names written as "Last, First". Type mismatches are behind many #VALUE! errors.

4. The result you expect, with an example

"Return Yes or No" is clearer than "check if". An example is better still: "for a start date of 2026-03-10 and an end date of 2026-03-14 the answer should be 4". The example settles questions you did not think to answer, such as whether the end day is counted.

5. The awkward cases

Decide what should happen when a cell is blank, when nothing matches, or when there are duplicates. "Show an empty cell if the ID is not found" turns a formula that works on the demo row into one that works on the whole column.

Before and after

VagueSpecific
lookup priceGoogle Sheets. Product name is in A2. Products are in Sheet2 column A, prices in Sheet2 column C. Return the price, or "Not found".
count late ordersExcel. Due dates in D2:D300, delivery dates in E2:E300. Count rows where the delivery date is later than the due date. Ignore rows where E is blank.
bonus formulaExcel 2019. Sales in B2. Bonus is 10% of sales above 50,000, 5% between 20,000 and 50,000, otherwise 0.

Check the answer before you rely on it

A formula that looks right can still be wrong for your data. Three quick checks:

  1. Test on rows where you know the answer. Pick three or four, including an edge case such as a blank cell.
  2. Read the explanation. If the description of what the formula does is not what you meant, the formula is not what you want, even if it returns a plausible number.
  3. Compare against a manual total. For sums and counts, filter the data and look at the status bar total for the same rows.

If the result is wrong, do not start over. Say what happened: "this returns 0, the dates in column A are text like 03/10/2026". The correction is usually one function away.

A template you can reuse

[Excel or Google Sheets, version]. [What is in each column and which rows]. [What I want returned]. [What to do with blanks, errors or no match]. Example: [input] should give [output].

It takes thirty seconds longer to write than a five-word request, and it usually saves the three rounds of corrections that follow one.

Need a formula for your own sheet?

Describe the task in plain English and get the formula, an explanation and a worked example.

Try the formula generator