StepGleam logoStepGleam
Excel guide

Run a Python analysis in Excel with Copilot's Advanced Analysis

Put the data in a Table in a cloud-saved workbook, start Advanced Analysis in Copilot, let it write Python cells, and read each one before you reuse the code.

~35 minIntermediate 74/100 5 steps Updated Oct 26, 2026
Copilot in ExcelPython in ExcelExcel (Microsoft 365)
Run a Python analysis in Excel with Copilot's Advanced Analysis — illustration for this Excel guide

Tools used

Step navigator0/5 done
0 of 5 steps done
What you'll get

Python cells in your workbook that you have read, re-run and checked against the source table.

Who this is for

Excel users who want forecasts or charts Excel cannot do natively, without learning Python first.

Read this first

Before you start

People on r/excel are mostly unimpressed by Copilot for everyday formulas, but several point to its ability to write Python in Excel as the useful part. One user explains how they start it and what they do with the code afterwards; a data-science blogger documents the setup.

Step-by-step instructions

Step 1 of 5 · Excel

Put the data in a Table and save the workbook to the cloud

Copilot needs the data in an Excel Table and the file on OneDrive or SharePoint. One user's complaint: "the data needs to be in a table. It will also only work if you store your file in oneDrive or sharepoint." Turn on AutoSave, choose a cloud location, then reopen the file from there.

Run a Python analysis in Excel with Copilot's Advanced Analysis — guide thumbnail
Step 2 of 5 · Excel

Click in the table and start Advanced Analysis

Click inside the table, open Copilot, ask it to start advanced analysis, then select Start. One r/excel user: "First prompt is 'Python'. They should show you a button for 'Start Advanced Analysis'." Copilot adds a new sheet for its Python cells.

Copy-ready promptCopilot in Excel
Please start advanced analysis.
Step 3 of 5 · Excel

Ask for one analysis at a time

Ask for one specific result, such as a forecast or a chart. Microsoft's example prompt is "Forecast sales for the next 4 quarters", and Copilot keeps the context of earlier asks so you can build step by step. When the Python errors, the r/excel user says Copilot will "even rewrite it if the first Python generates an error."

Copy-ready promptCopilot in Excel
The Sales table has one row per month. Create a DataFrame indexed by month and forecast the next 4 quarters. Show the code and a chart.
Why this works

One ask at a time keeps each cell easy to check.

Step 4 of 5 · Excel

Expect different results on different runs, and read the code

The blogger who documented this notes that Copilot sometimes only loads the table and sometimes runs extra analyses: "There is a certain level of randomness." Open each Python cell and read what it computes before trusting the output.

Why this works

Knowing what the code does is the only way to catch a wrong analysis.

Step 5 of 5 · Excel

Copy the working code into your real workbook

Once a cell does what you want, reuse it. The r/excel user: "Once Copilot writes some useful Python, I will copy it back to my real workbooks (with AutoSave off) for further use."

End of guide · Reviewed Oct 26, 2026

Pro tips2
  • Keep a scratch copy for Copilot experiments and copy only finished code into your real file.
  • Ask Copilot to explain each line of the Python it wrote; users treat this as a way to learn Python.
Common mistakes3
  • Starting Advanced Analysis on a range that is not a Table.
  • Accepting a forecast without reading which columns the code used.
  • Experimenting on the real file with AutoSave on.
FAQ2
Do I need to know Python?
No, but you should read the code it writes.
What do I need to have?
Python in Excel and a Microsoft 365 Copilot licence, per Microsoft.