Ravindra BagaleCourses & study guides Track your progress

Guides · Generative AI

How to Write Excel Formulas with ChatGPT and Copilot (7 Worked Examples)

To get a correct Excel formula from ChatGPT, tell it where your data is (sheet, range, headers), what result you want and which cell it goes in, and your Excel version. Paste the formula, then check it on 2 or 3 rows by hand. In Excel itself, use the Copilot pane (the Copilot icon at the lower right) with a Microsoft 365 plan that includes Copilot. The old =COPILOT() cell function was retired on 14 September 2026.

Most people know what they want from Excel, but not the formula. "Total of Pune tea sales" is easy to say and hard to write as SUMIFS. AI tools are very good at this translation, if you describe your sheet clearly. They are also very good at writing a formula that looks right and points at the wrong column. In this guide we use one small sales sheet and build 7 real formulas with ChatGPT, each checked by hand, and then do the same work with Copilot inside Excel.

Full course chapter

This guide gives 7 quick examples. The course chapter is the full lesson, tested on a free practice file: XLOOKUP and the VLOOKUP trap, duplicates, GST with IF, fixing errors and Copilot not showing, with a quiz. Read it here: ChatGPT and Copilot for Excel Formulas: Write, Explain and Fix Formulas.

What you will learn in this guide

  • The 4-part formula prompt
  • SUMIFS, COUNTIFS and XLOOKUP by AI
  • IF labels and date totals
  • Fix a #N/A error with AI
  • Explain a long formula
  • Use Copilot inside Excel

1. Suppose we manage sales for a tea and coffee distributor

Suppose we are Pooja. We work for a small tea and coffee distributor that supplies shops in Pune, Mumbai and Nashik. Our manager sends a WhatsApp: "How much Tea did we sell in Pune this month? And how many Coffee orders came from Mumbai?"

Here is our sheet, named Sales. Copy this table into a new Excel sheet starting at cell A1, so you can follow every example.

OrderID Date City Product Amount
1001 01-10-2026 Pune Tea 1200
1002 02-10-2026 Mumbai Coffee 800
1003 02-10-2026 Pune Coffee 950
1004 03-10-2026 Nashik Tea 600
1005 04-10-2026 Pune Tea 1500
1006 05-10-2026 Mumbai Tea 700
1007 06-10-2026 Nashik Coffee 1100
1008 07-10-2026 Pune Sugar 300
1009 08-10-2026 Mumbai Coffee 1250
1010 09-10-2026 Pune Coffee 400

So the data is in A1:E11: headers in row 1, 10 orders in rows 2 to 11. The dates are real Excel dates (day-month-year, as in India).

2. The 4-part formula prompt

A weak prompt is: "excel formula for total". The AI does not know your columns, so it guesses =SUM(A:A), which adds up order IDs.

A strong prompt has 4 parts:

Part What to write Example
Data Sheet name, range, what each column holds "Sheet Sales, A1:E11. A=OrderID, B=Date, C=City, D=Product, E=Amount"
Goal The result in plain words "Total Amount where City is Pune and Product is Tea"
Place Where the formula goes, and any input cells "Formula in H2"
Version and output Your Excel and what you want back "Excel for Microsoft 365. Give one formula and explain each part in simple words"

Copy this template and reuse it for every formula:

I use Excel for Microsoft 365. My data is in sheet "Sales", range A1:E11,
headers in row 1:
A = OrderID, B = Date (real dates), C = City, D = Product, E = Amount.
Goal: [what you want, in plain words]
Put the formula in cell [H2]. [Any input cell, e.g. "the order ID is typed in G2"]
Give one formula, then explain each part in simple English.

Ravindra Bagale's Tip

Students paste the AI's formula and trust the answer. Always check 2 or 3 rows with your own eyes or a calculator. If the formula says 2,700 and you can see 1,200 + 1,500 in the sheet, then you know it is right.

3. Example 1: total with two conditions (SUMIFS)

Goal: total Tea sales in Pune.

[template] Goal: total Amount where City is "Pune" and Product is "Tea". Put it in H2.

Expected formula (the AI's wording will differ, the formula should match):

=SUMIFS(E2:E11, C2:C11, "Pune", D2:D11, "Tea")

What it means: add the values in E2:E11, only for rows where C is "Pune" and D is "Tea".

Result: 2700.

Check by hand: Pune Tea rows are 1001 (1,200) and 1005 (1,500). 1,200 + 1,500 = 2,700. Correct.

4. Example 2: count with two conditions (COUNTIFS)

Goal: how many Coffee orders came from Mumbai.

=COUNTIFS(C2:C11, "Mumbai", D2:D11, "Coffee")

Result: 2 (orders 1002 and 1009).

5. Example 3: find a value by ID (XLOOKUP)

Goal: type an order ID in G2 and get its Amount in H2. Show "Not found" if the ID does not exist.

=XLOOKUP(G2, A2:A11, E2:E11, "Not found")

Test: type 1007 in G2. Result: 1100. Type 2000. Result: Not found.

If you use an older Excel without XLOOKUP (for example Excel 2016), say so in the prompt. The AI will give you =IFERROR(VLOOKUP(G2, A2:E11, 5, FALSE), "Not found") instead, which does the same job here. This is why the version line in the prompt matters.

6. Example 4: a label for each row (IF)

Goal: in F2, label each order "High" if Amount is 1000 or more, "Medium" if 500 or more, otherwise "Low". Then copy it down to F11.

=IF(E2>=1000, "High", IF(E2>=500, "Medium", "Low"))

In Microsoft 365 you can also ask for the shorter IFS version:

=IFS(E2>=1000, "High", E2>=500, "Medium", TRUE, "Low")

Check: row 2 (1,200) shows High, row 5 (600) shows Medium, row 9 (300) shows Low.

7. Example 5: total between two dates

Goal: total Amount from 1 October to 5 October 2026.

=SUMIFS(E2:E11, B2:B11, ">="&DATE(2026,10,1), B2:B11, "<="&DATE(2026,10,5))

Result: 5750 (orders 1001 to 1006: 1,200 + 800 + 950 + 600 + 1,500 + 700).

Why DATE()? Writing the date as text, like ">=01-10-2026", can be read as 10 January on a computer with US date settings. DATE(year, month, day) is always clear. A good AI answer uses it; if yours does not, ask: "Use DATE() so it works with any date settings."

8. Example 6: fix a #N/A error with AI

Suppose a colleague types Pune (with a space at the end) in cell J2, and this formula shows #N/A:

=XLOOKUP(J2, C2:C11, E2:E11)

Ask the AI to find the problem. Give it the formula, the error, and what you see in the cell:

This Excel formula returns #N/A: =XLOOKUP(J2, C2:C11, E2:E11)
J2 looks like "Pune" and C2:C11 contains Pune. What are the common reasons,
and how do I fix it? Give the fixed formula.

Expected answer (similar, not the same): the most common reason is extra spaces or a different spelling. Fix it with TRIM:

=XLOOKUP(TRIM(J2), C2:C11, E2:E11, "Not found")

Result: 1200. XLOOKUP returns the first match, which is order 1001. If you wanted the total for Pune, the right formula is SUMIFS, not XLOOKUP, so say "total" in your prompt when you mean total.

9. Example 7: explain a formula someone else wrote

You open an old file and see this:

=IFERROR(SUMIFS(E2:E11, C2:C11, G5, D2:D11, H5) / COUNTIFS(C2:C11, G5, D2:D11, H5), 0)

Prompt:

Explain this Excel formula step by step for a beginner, in simple English,
and tell me what it returns if G5 = "Pune" and H5 = "Coffee":
[paste the formula]

Expected answer (similar): it finds the average Amount for the city in G5 and product in H5 (total divided by count), and shows 0 if there are no matching rows. For Pune Coffee: (950 + 400) / 2 = 675.

You can also ask: "Is there a simpler formula?" The AI should suggest =IFERROR(AVERAGEIFS(E2:E11, C2:C11, G5, D2:D11, H5), 0), which gives the same 675.

10. Doing the same with Copilot inside Excel

Copilot works inside your workbook, so it can see your columns. You do not need to describe the range as carefully.

  1. Click inside your data and press Ctrl + T to make it an Excel table. Copilot works best with clean tables: one header row, no merged cells.
  2. Click the Copilot icon at the lower right of Excel.
  3. Choose a mode. Edit changes the workbook, Plan shows a plan for you to approve first, and Chat answers without changing anything (these three modes are on Windows, Mac and the web).
  4. Type: "Add a formula in a new column that labels each order High if Amount is 1000 or more, Medium if 500 or more, otherwise Low."
  5. Click into the new column and read the formula Copilot wrote. Check 2 or 3 rows.

Who gets Copilot in Excel (October 2026)? Microsoft's support page lists: Microsoft 365 Personal or Family with AI credits, Microsoft 365 Premium, or an eligible business or Copilot plan. Microsoft's credits page says Personal and Family include 60 AI credits a month for Copilot in the Office apps, and Premium has much higher use. Check your plan in your Microsoft account before you buy.

The =COPILOT() function is gone. Microsoft retired it on 14 September 2026. Old cells that used it show #NAME? after they recalculate. Use the Copilot pane instead.

For 40 more Copilot prompts with a checking routine, see our Copilot in Excel prompts for analysts guide.

11. ChatGPT, Gemini, Claude or Copilot?

Tool Best use for formulas Watch out for
ChatGPT, Gemini, Claude (free plans) Writing and explaining formulas from your description They cannot see your sheet; describe the range and headers exactly
Copilot in Excel (paid plan) Adding formulas and columns directly in your workbook Read every formula it adds before you share the file
Any of them Fixing errors like #N/A, #VALUE!, #SPILL! Paste the exact formula and the exact error

Privacy: do not paste salary sheets, customer phone numbers or client data into a free AI chat. Describe the columns, or use 5 fake rows like the table above.

12. Beginner mistakes and quick fixes

Mistake Quick fix
"Give me a total formula" with no range Use the 4-part prompt: Data, Goal, Place, Version
Trusting the result without checking Check 2 or 3 rows by hand every time
Not saying your Excel version Say "Excel 365" or "Excel 2016"; it decides XLOOKUP vs VLOOKUP
Dates written as text in the formula Ask for DATE(year, month, day)
Asking for a lookup when you need a total Use the word "total" or "sum" for SUMIFS
Pasting real customer data into a free chat Use fake sample rows and the same column names

13. Try at home

Try at home

  1. Copy the Sales table into Excel at A1.
  2. Use the template in section 2 to get a formula for: "total Coffee sales in all cities".
  3. Check the answer by hand. (Hint: 800 + 950 + 1,100 + 1,250 + 400.)
  4. Ask for a formula that counts orders above 1,000. Check it by hand.
  5. Break a formula on purpose (add a space after "Pune" in your input cell) and ask the AI to fix the error.
  6. If you have Copilot in Excel, make the data a table and ask Copilot for the High/Medium/Low column. Compare its formula with Example 4.

Recap

In short

  1. Give the AI 4 things: Data (sheet, range, headers), Goal, Place (cell), and Version and output.
  2. SUMIFS totals with conditions, COUNTIFS counts with conditions, XLOOKUP finds a value by ID.
  3. Use DATE() for date conditions so it works with any date settings.
  4. For errors, paste the exact formula and the exact error; TRIM fixes many #N/A problems.
  5. Copilot in Excel works in the Copilot pane on eligible Microsoft 365 plans; the =COPILOT() function was retired on 14 September 2026.
  6. Always check 2 or 3 rows by hand before you trust or share a formula.

Take one formula you use at work every week, ask the AI to explain it with the prompt in Example 7, and you will understand your own sheet better by tomorrow.

Learn prompts properly: Prompt Engineering for Beginners: Role, Task, Context and Format


Ravindra Bagale, trainer: linkedin.com/in/ravindra-bagale. Pooja, the distributor and all orders and amounts are made up for learning. Every formula result on this page was checked against the sample table. Copilot plans, credits, modes and the =COPILOT() retirement were checked on Microsoft's support pages on 19 October 2026 and can change. AI answers change every time, so the wording you get will be different.

Frequently asked questions

Can ChatGPT write Excel formulas?

Yes. Describe the sheet, range, headers, the result you want, the cell and your Excel version. Then check the formula on 2 or 3 rows by hand.

Is the =COPILOT() function still available in Excel?

No. Microsoft retired the COPILOT function on 14 September 2026. Use the Copilot pane in Excel instead.

Do I need to pay for Copilot in Excel?

Yes, you need an eligible plan, such as Microsoft 365 Personal or Family with AI credits, Microsoft 365 Premium, or an eligible business plan.

Why does the AI formula give the wrong answer?

Usually the prompt did not say the exact columns, the Excel version, or whether you wanted a total or a lookup. Give all four parts of the prompt.

Is it safe to paste my Excel data into ChatGPT?

Do not paste private data like salaries or customer phone numbers. Describe the columns, or use a few fake rows with the same headers.

Related: ChatGPT and Copilot for Excel Formulas: Write, Explain and Fix