- Home
- Guides
- AI Builder & AI
- How to extract invoice data to Excel automatically with AI Builder and Power Automate
How to extract invoice data to Excel automatically with AI Builder and Power Automate
Build two Power Automate flows that read invoices with a custom AI Builder prompt and save every line item to Excel: one processes a whole OneDrive folder of invoices, the other lets you snap a photo of a paper invoice with the Power Automate mobile app.
Jump to a step (12)
Small businesses and accounts payable staff often retype vendor names, invoice numbers, dates and line items from every invoice into a spreadsheet. It is slow, error-prone and piles up at month end. An AI prompt can read any invoice layout and fill the Excel table for you.
Instead of the pre-built invoice model, which needs training with sample documents, this build uses a custom prompt in AI Builder. The prompt returns a JSON array with one element per line item, so each field maps straight to an Excel column.
The first flow lists every file in a OneDrive folder, runs the prompt on each one and adds a row per line item. The second is a copy of the first, changed to take a single file or camera photo from the Power Automate mobile app.
What you need
- Power Automate with access to AI Builder prompts (the Run a prompt action is premium and uses AI Builder credits)
- An Excel file in OneDrive for Business with a table for the invoice data
- A OneDrive folder holding the invoices to process (PDF, PNG or JPEG)
- The Power Automate mobile app for the phone scanner version
Step by step
0 of 12 done-
01
Create a custom prompt in AI Builder
In Power Automate, go to AI hub and select Prompts, then Build your own prompt. (Under AI models there is a pre-built invoice model, but it needs training with sample documents. A custom prompt works right away.)
In the instructions, ask the model to extract
Vendor Name,Invoice Number,Invoice Date,Due Date,Item Name,Quantity,Unit PriceandAmount, and to return a JSON array where each element is one line item. The prompt in the video also includes:- Normalization rules: a fixed date format, and plain numbers with no currency symbols or commas
- Missing values: an empty string for text and
0for numbers - Calculation rules: if the unit price is missing, divide amount by quantity. If the amount is missing, multiply unit price by quantity
-
02
Add the document input and set JSON output
Delete the document placeholder text in the instructions, then use Add content and choose Image or document so the prompt accepts a file.
The default model is GPT-4.1 mini, which is fast and cost effective for this task. Under the model response settings, change the output format to
JSONso the result can be mapped to Excel columns. -
03
Test the prompt and save it
Upload a sample invoice to the document input and click Test. Within a few seconds you should see the vendor name, invoice number, dates and each line item, formatted as you asked. Name the prompt (in the video: Invoice Data Extractor) and save it.
-
04
Prepare the Excel table
Create an Excel file in OneDrive (in the video: Invoice Data Log) with the headers
Vendor Name,Invoice Number,Invoice Date,Due Date,Item Name,Quantity,Unit PriceandAmount.Select the headers, choose Format as Table, pick a style, tick My table has headers and click OK. The table name shows under Table Design (the default is
Table1). -
05
Create the flow and list the invoice files
Select Create, then Instant cloud flow. Name it (Extract Invoice Data), choose Manually trigger a flow and click Create.
Add the OneDrive for Business action List files in folder and use the folder picker to select the folder that holds your invoices.
-
06
Loop through the files and get their content
Add Apply to each from Control and set its input to the output (
value) of List files in folder, so each file is processed one at a time.Inside the loop, add the OneDrive for Business action Get file content and set File to the
Idfrom List files in folder. The Id uniquely identifies each file. -
07
Run the prompt on each invoice
Still inside the loop, add Run a prompt from AI capabilities. Select your Invoice Data Extractor prompt. For the document input, pick the
File Contentoutput of Get file content. -
08
Add each line item to Excel
Add the Excel Online (Business) action Add a row into a table. Set Location to
OneDrive for Business, Document Library toOneDrive, pick the Invoice Data Log file andTable1.Expand Advanced parameters, select all columns, and map each one to the matching field from Run a prompt (use See more to find them):
Vendor Name,Invoice Number,Invoice Date,Due Date,Item Name,Quantity,Unit PriceandAmount. Because the prompt returns an array of line items, Power Automate places the Excel action in its own loop so one row is added per line item. Save the flow. -
09
Test bulk processing
Put a few invoices in the folder, click Test, choose Manually, then Continue and Run flow. Watch the Excel file: rows appear for each line item of each invoice.
-
10
Copy the flow for the mobile scanner
Use Save As to copy the flow (Extract Invoice Data Mobile). Open the copy, turn it on and edit it.
A phone capture handles one invoice at a time, so you do not need the folder listing or the file loop. Drag Run a prompt directly under the trigger, drag the line item loop with the Excel action under it, then delete List files in folder, the outer Apply to each and Get file content.
-
11
Add a file input to the trigger
Select the Manually trigger a flow trigger, click Add an input and choose File. This lets you upload a file or take a photo when you run the flow from your phone.
In Run a prompt, clear the old document input and set it to the file content (
contentBytes) from the trigger. The Excel mapping stays the same. -
12
Scan an invoice from your phone
Open the Power Automate mobile app, find the mobile flow, tap the three dots and choose Run flow. Tap the file input, choose Launch the camera, photograph the invoice, tap Use photo, then Run flow. The data lands in the Excel table within seconds.
Tips and common problems
- Use a custom prompt rather than the pre-built invoice model if you do not want to train a model with sample documents. The prompt works with any invoice layout straight away.
- Set the prompt's output format to JSON. Without it, Power Automate cannot map the individual fields to Excel columns.
- Tell the prompt to return plain numbers without currency symbols or commas, and a single date format, so Excel stores them as numbers and dates.
- The bulk flow handled 50 invoices in one run in my test. For large batches, keep the files in the folder and run the folder version rather than the mobile one.
- Run a prompt is an AI Builder action. It needs a premium Power Automate licence and uses AI Builder credits, so check what your tenant includes before rolling it out.
Quick version
The short AI extracts invoice data to Excel from a phone photo or PDF shows the end result in under a minute: open the Power Automate mobile app, photograph an invoice, and the vendor, invoice number, dates, line items, quantities and amounts appear in Excel. The same approach works for receipts, purchase orders and delivery notes.
Related builds
Questions
Can Power Automate extract data from invoices into Excel?
Yes. A custom AI Builder prompt reads each invoice and returns the fields as JSON, and the Excel Online (Business) action Add a row into a table writes each line item as a new row.
Do I need to train an AI model to read invoices?
Not with this method. The pre-built invoice model in AI hub needs training with sample documents, but a custom prompt with clear extraction rules works immediately.
Does this work with photos of paper invoices?
Yes. The mobile version adds a File input to the manual trigger, so you can take a photo in the Power Automate mobile app and the prompt extracts the data from the image. It also works with PDF, PNG and JPEG files.
Is AI Builder included in Microsoft 365 Business Standard?
Not on its own. Running AI Builder prompts in a flow is a premium feature that uses AI Builder credits, so you need a licence or add-on that provides them.
