# 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.

- **Category:** [Excel](https://stepgleam.com/categories/excel)
- **Difficulty:** Intermediate
- **Time:** ~35 minutes
- **Tools:** Copilot in Excel, Python in Excel, Excel (Microsoft 365)
- **Reliability score:** 74/100
- **Steps:** 5
- **Last updated:** 2026-10-26
- **Published:** 2026-10-26

## Tools used

- [Copilot in Excel](https://support.microsoft.com/en-us/excel/copilot/get-started-with-copilot-in-excel) — Writes and fixes the Python cells
- [Python in Excel](https://support.microsoft.com/en-us/office/get-started-with-python-in-excel-a33fbcbe-79ec-4eeb-9af7-16a2e3d1a2ea) — Runs the analysis inside the workbook
- [Excel (Microsoft 365)](https://support.microsoft.com/en-us/excel) — Holds the source Table

## 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.

## 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.

## Steps

### Step 1: Put the data in a Table and save the workbook to the cloud

**Tool:** Excel (Microsoft 365)

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.

[Open step 1](https://stepgleam.com/guides/run-python-analysis-in-excel-with-copilot-advanced-analysis#step-1)

### Step 2: Click in the table and start Advanced Analysis

**Tool:** Copilot in Excel

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.

**Prompt:**

```
Please start advanced analysis.
```

[Open step 2](https://stepgleam.com/guides/run-python-analysis-in-excel-with-copilot-advanced-analysis#step-2)

### Step 3: Ask for one analysis at a time

**Tool:** Copilot in Excel

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."*

**Why this works:** One ask at a time keeps each cell easy to check.

**Prompt:**

```
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.
```

[Open step 3](https://stepgleam.com/guides/run-python-analysis-in-excel-with-copilot-advanced-analysis#step-3)

### Step 4: Expect different results on different runs, and read the code

**Tool:** Python in Excel

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.

[Open step 4](https://stepgleam.com/guides/run-python-analysis-in-excel-with-copilot-advanced-analysis#step-4)

### Step 5: Copy the working code into your real workbook

**Tool:** Python in Excel

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."*

[Open step 5](https://stepgleam.com/guides/run-python-analysis-in-excel-with-copilot-advanced-analysis#step-5)

## Pro tips

- 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 mistakes

- 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.

## FAQ

### 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.

---

Canonical guide: https://stepgleam.com/guides/run-python-analysis-in-excel-with-copilot-advanced-analysis
Read this guide as Markdown: https://stepgleam.com/guides/run-python-analysis-in-excel-with-copilot-advanced-analysis.md
