AI for Data Analysis & Decision MakingWriting formulas, SQL and Python with AI, and verifying them · Lesson 7 of 16

Spreadsheet formulas with AI

Article · 10 min · 8 min lecture

Video lecture

Spreadsheet formulas with AI

15 chapters · about 8 min · full transcript

Coming soon

Chapter 1 of 15

Spreadsheet formulas with AI

  • Formulas are verifiable artifacts
  • Describing what you need
  • Verification techniques
  • Modern, readable functions
  • A checks sheet

The narrated lecture is in production

Every chapter is scripted and ready. Browse the chapters and read the full transcript now — the video will appear here when it’s published.

Chapters

Why formulas are a sweet spot

Spreadsheets remain the most widely used analysis tool in business. AI assistants (including those built into spreadsheet tools) can write formulas from plain-language descriptions, explain inherited formulas, and debug errors. The result is a formula you can see, test and reuse, which is inherently more verifiable than a number stated in chat.

Describing what you need

Give the AI the layout and the logic:

Sheet "Orders": A = order_date, B = country, C = channel, D = revenue.
Sheet "Summary": A2:A7 = countries, B1:G1 = months as dates (first of month).
Write a formula for B2 that sums revenue for the country in A2 and the
month in B1, which I can fill across and down. Use Excel. Explain it.

Mention which tool (Excel, Google Sheets, others), since functions and syntax differ, and specify the locale if relevant (some locales use semicolons as argument separators).

Example output and explanation

=SUMIFS(Orders!$D:$D, Orders!$B:$B, $A2,
        Orders!$A:$A, ">="&B$1, Orders!$A:$A, "<"&EDATE(B$1,1))

The explanation should cover the mixed references ($A2 locks the column, B$1 locks the row) so filling works, and the date range logic (from the first of the month up to, but not including, the first of the next month).

Explaining and debugging

  • Explain: paste an inherited formula and ask "Explain step by step what this does and any edge cases where it could give wrong results."
  • Debug: paste the formula, the error or wrong result, and a few sample rows: "This returns #N/A for some rows; here are three of them."
  • Refactor: "Rewrite this nested IF as something easier to maintain."

Verification techniques for formulas

  1. Hand-check a few cells. Filter the source data for one country and month, sum it manually (or with the status bar), and compare.
  2. Reconcile totals. The sum of your summary table should equal the total of the source column (for the covered period). If not, something is double-counted or missed.
  3. Test edge cases: blanks, zero values, text in number columns, dates at month boundaries, spelling variants ("UK " with a trailing space).
  4. Check fill behavior: after filling, spot-check a far corner cell to confirm references moved correctly.
  5. Watch for silent failures: lookups that return the wrong match because of approximate matching defaults, or errors wrapped in IFERROR that hide real problems.

Common AI formula mistakes

  • Using a function not available in your tool or version.
  • Wrong reference locking, so filled formulas drift.
  • Approximate instead of exact matching in lookups.
  • Off-by-one date ranges (including the first day of the next month).
  • Assuming clean data (trailing spaces, numbers stored as text).

Worked example: commission calculation

A sales manager asks for a tiered commission formula: 5% up to a threshold, 8% above it, plus a bonus if the target is met. The AI's first formula applies 8% to the whole amount once the threshold is exceeded, rather than only to the portion above it. The manager catches it by testing three example salespeople whose commissions she calculates by hand: one below the threshold, one just above, one far above. The corrected formula passes all three. Tiered logic is exactly where a few hand-calculated test cases pay off.

Documenting formulas for colleagues

Ask the AI to add a short note beside complex formulas (what it calculates, its inputs and any assumptions, such as "revenue excludes refunds"). Workbooks outlive their authors; a one-line explanation prevents the next person from breaking a formula they don't understand.

Hands-on: modern formulas worth asking for

Current Excel (Microsoft 365) and Google Sheets support functions that make AI-written formulas easier to read and test. Ask for them by name when your version supports them:

=LET(rev, Orders!D:D, cty, Orders!B:B, dt, Orders!A:A,
     start, B$1, finish, EDATE(B$1, 1),
     SUMIFS(rev, cty, $A2, dt, ">=" & start, dt, "<" & finish))

=XLOOKUP(A2, Customers!A:A, Customers!C:C, "NOT FOUND", 0)      exact match, explicit not-found

=FILTER(Orders!A:D, (Orders!B:B = "UAE") * (Orders!D:D > 1000), "none")

LET names each part so a reviewer can read the logic; XLOOKUP with an explicit not-found value avoids silent wrong matches.

Hands-on: a checks sheet in five formulas

A1 Source total        =SUM(Orders!D:D)
A2 Summary total       =SUM(Summary!B2:G7)
A3 Totals reconcile?   =ABS(A1 - A2) < 0.01
A4 Blank countries     =COUNTBLANK(Orders!B2:B20000)
A5 Unknown countries   =SUMPRODUCT(--ISNA(MATCH(Orders!B2:B20000, Lists!A:A, 0)))

In Microsoft 365, you can also ask Copilot in Excel to explain a formula or suggest one, or use Python in Excel for analysis that is awkward in formulas. With the Claude for Excel add-in or Google Sheets' Gemini features, the same rule applies: the formula is the deliverable, and you test it with hand-calculated cases.

Second worked example: a UAE property manager's service charges

A property manager asks for a formula that allocates building service charges by unit size, with a minimum charge for small units. The first AI formula applies the minimum after allocation, so totals no longer match the building's actual costs. The manager's checks sheet flags that the allocated total exceeds the invoice. The corrected version allocates the remainder after minimums proportionally. Three hand-calculated test units and the reconciliation check both pass.

Going further

For important workbooks, build a small "checks" sheet: reconciliation totals, counts of blanks, and flags for values outside expected ranges, each showing TRUE or FALSE. Ask the AI to write these check formulas. A glance at the checks sheet before sharing catches most errors.

Key takeaways

  • Formulas are verifiable artifacts; prefer them to numbers stated in chat.
  • Describe sheet layout, logic, tool and locale; ask for an explanation.
  • Verify by hand-checking cells, reconciling totals, testing edge cases and checking fill behavior.
  • Tiered and date-boundary logic are common failure points; test with hand-calculated examples.

Check your understanding

Quick questions to lock in the lesson. They don’t count towards your certificate.

  1. Your summary table total does not match the source column total for the same period. What does this suggest?
  2. A tiered commission formula should be tested with which examples?
  3. Why tell the AI which spreadsheet tool and locale you use?

Put it into practice

Ask an AI to write one formula you need this week. Verify it with three hand-calculated test cases and a reconciliation total.

Enrol for free to save your progress

Reading is always free. Enrol to keep your place, take the final assessment and earn a verifiable certificate.