The Excel.Workbook function in Power Query opens another Excel file and lists everything inside it: its sheets, Excel Tables, and named ranges. From that list, you pick the one you want and load its data.
Once you know how to write it yourself, you can pull a sheet by name, stack several sheets into one table, or combine every file in a folder. And when the source file changes, you just refresh.
In this article, I’ll show you how Excel.Workbook works with practical examples, from reading a single sheet to combining files from a whole folder.
Follow along with the example file
Excel.Workbook Function Examples.zip
Excel.Workbook Function Syntax
Excel.Workbook(workbook as binary, optional useHeaders as any, optional delayTypes as nullable logical) as table
- workbook – the Excel file you want to read, as binary content. You almost always get this with the File.Contents function, like
File.Contents("C:\Sales\Store Sales.xlsx"), or from the Content column of the Folder.Files function. - useHeaders (optional) – set it to
trueto use the first row as headers, or leave it atfalseto keep that row as data. When the third argument isnullor omitted, you can pass an options record here with fields such asUseHeaders,DelayTypes, andInferSheetDimensions. - delayTypes (optional) – set it to
trueto leave every column without a data type, so you can set the types yourself. The default isfalse, which lets Power Query detect types where it can.
What it returns: A table with one row for each sheet, Excel Table, and named range in the file. It has five columns: Name, Data, Item, Kind, and Hidden.
The Data column holds the actual content of each item as a table, and Kind tells you whether the row is a Sheet, a Table, or a DefinedName (a named range).
Item holds the item’s real name, which is what the examples below use to pick one.
The Excel.Workbook function is part of the core Power Query M library, so it works wherever Power Query does, including Excel 365, 2024, 2021, 2019, 2016, and Power BI.
When to Use the Excel.Workbook Function
Use this function when you need to:
- Pull data from a sheet, Excel Table, or named range in another workbook
- See every sheet, table, and named range a workbook holds before picking one
- Skip hidden sheets or sheets that don’t follow a naming pattern
- Stack monthly or regional sheets from one workbook into a single table
- Combine the same sheet from every Excel file in a folder
How the Example Files Work
Excel.Workbook reads a separate file, so this download is a zip with three parts. There’s the examples workbook with all the queries, a Store Sales.xlsx workbook that the queries read, and a Regional Sales folder with three small files for the last example.
Store Sales.xlsx has three month sheets (Jan 2026, Feb 2026, Mar 2026), a Products sheet with an Excel Table named Products, and a Settings sheet with a named range called RegionTargets. It also has a hidden sheet, Dec 2025.
The queries don’t type the file path into every formula. Instead, they use two parameters: SourceFile holds the full path to Store Sales.xlsx, and SalesFolder holds the path to the Regional Sales folder.
If you unzip the download into C:\Users\Public\Documents, you get a folder called C:\Users\Public\Documents\Excel.Workbook Function Examples, and the queries work as they are.
Check that Store Sales.xlsx sits directly inside that folder. If it ends up one folder deeper (inside a second folder with the same name), the queries can’t find the files, so move the files up a level or change the parameters.
If you save the files somewhere else, open the Power Query Editor, go to Home > Manage Parameters, and change both paths. The Start Here sheet in the examples workbook lists these steps too.
In your own file, you can skip the parameter and type the path straight into the formula, like File.Contents("C:\Sales\Store Sales.xlsx"). A parameter just makes the path easy to change later.
Example 1: See Everything Inside a Workbook
Let’s start with the basic use. You have a workbook, and before you pull any data from it, you want to see what’s inside.
In Store Sales.xlsx, you can see five sheet tabs (three month sheets, Products, and Settings). I want to list every sheet, table, and named range it holds, including anything I can’t see from the tabs.
In Excel, go to Data > Get Data > From Other Sources > Blank Query. In the Power Query Editor, open the Advanced Editor (Home > Advanced Editor) and use this code:
let
Source = Excel.Workbook(File.Contents(SourceFile))
in
Source
Result: A table with eight rows: six sheets, one Excel Table, and one named range

Here, the File.Contents function reads the file, and Excel.Workbook turns it into a table with one row per item.
The Kind column tells you what each row is. You can see six rows of kind Sheet, one Table (the Products table), and one DefinedName (the RegionTargets named range).
The Hidden column shows TRUE for the Dec 2025 sheet. Excel.Workbook still lists hidden sheets, so you can read their data even though you can’t see them in Excel.
Each Data cell holds the content of that item. Click on the word Table in any Data cell, and Power Query opens that item’s data (the sheet, table, or named range in that row).
Example 2: Get the Data from One Sheet
Now let’s pull the data from a single sheet. Say you only need the January orders from Store Sales.xlsx.
Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.Workbook(File.Contents(SourceFile)),
#"Jan 2026" = Source{[Item="Jan 2026",Kind="Sheet"]}[Data]
in
#"Jan 2026"
Result: The Jan 2026 sheet, with the headers (Order ID, Order Date, Product, Units, Amount) sitting in the first row and the columns named Column1 to Column5

Here, Source{[Item="Jan 2026",Kind="Sheet"]} finds the row in the list where the Item is Jan 2026 and the Kind is Sheet. Then [Data] gets the table stored in that row.
I match on Item and Kind, not Name, because Item always holds the item’s real name. Example 5 shows a case where the Name column is different.
Since we didn’t set useHeaders, the headers stay in row 1 as regular data. That’s why the columns are called Column1, Column2, and so on, and the next two examples fix that.
If the sheet name doesn’t match exactly (say you type “January”), you get the error “The key didn’t match any rows in the table.”
You’ll also see this error when someone renames the sheet in the source file, so check the sheet name first when it shows up.
Example 3: Use the First Row as Headers
In most sheets, the first row holds the column headers. Instead of promoting them in a separate step, you can ask Excel.Workbook to do it.
Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.Workbook(File.Contents(SourceFile),true),
#"Jan 2026" = Source{[Item="Jan 2026",Kind="Sheet"]}[Data]
in
#"Jan 2026"
Result: The Jan 2026 sheet with proper column headers (Order ID, Order Date, Product, Units, Amount) and four orders

Here, the second argument is true, so Excel.Workbook uses the first row of every sheet as its headers. It also detects the data types, so Order Date comes in as a date and Units and Amount come in as numbers.
This works well when your headers are plain text, like the ones here. There’s one catch, though, when a header is a number or a date.
Example 4: Promote Headers the Way Microsoft Recommends
Some sheets use numbers or dates as headers, like a budget with 2025 and 2026 as column names, or a sheet with one column per month-end date.
Microsoft’s documentation warns that useHeaders turns such headers into text using the computer’s regional settings. So a date header can become a different column name on a US computer than on a UK computer.
When that happens, any later step that refers to the column by name breaks on the other machine.
Microsoft’s recommended fix is to keep the headers out of Excel.Workbook and promote them with the Table.PromoteHeaders function. Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.Workbook(File.Contents(SourceFile),null,true),
#"Jan 2026" = Source{[Item="Jan 2026",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(#"Jan 2026",[PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Order ID",type text},{"Order Date",type date},{"Product",type text},{"Units",Int64.Type},{"Amount",type number}})
in
#"Changed Type"
Result: The same table as Example 3, with Order ID, Order Date, Product, Units, and Amount as headers and four orders

Here, the second argument is null, which leaves useHeaders at its default, so the headers stay in row 1. The third argument (delayTypes) is true, so Excel.Workbook doesn’t guess any data types while the headers are still sitting in the data.
Then the Table.PromoteHeaders function turns the first row into headers, and [PromoteAllScalars=true] lets it promote number and date headers too.
Since delayTypes leaves every column untyped, the last step assigns the types. Without the Changed Type step, Order Date would still have type any, and date filters wouldn’t show up for that column.
The result looks the same as Example 3 because these headers are plain text. For numbers or dates in the header row, use [PromoteAllScalars=true,Culture="en-US"] with Table.PromoteHeaders to get the same header names across Power Query locales.
Example 5: Get an Excel Table from the Workbook
If the data in the source file is formatted as an Excel Table, you can pull the table by its name instead of the sheet.
Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.Workbook(File.Contents(SourceFile)),
Products = Source{[Item="Products",Kind="Table"]}[Data]
in
Products
Result: The Products table with Product, Category, and Unit Price columns and four products

Here, we look for the row where the Item is Products and the Kind is Table. Notice that we didn’t set useHeaders, but the result still has proper headers, because an Excel Table always has a header row and Power Query uses it.
Pulling a table instead of a sheet is also safer. The table grows when someone adds rows to it, and it ignores any notes or totals sitting elsewhere on the sheet.
Now look back at the result of Example 1. The Products table shows up there with the Name Products1, while its Item is Products.
That happens because the Name column can’t have duplicates, and the Products sheet already uses that name. The Item column keeps the real name, which is why the lookups in this article use Item and Kind together, not Name.
Example 6: Get a Named Range
Excel.Workbook also lists named ranges, so you can pull a range that someone has given a name, without worrying about which sheet it’s on.
In Store Sales.xlsx, the range with the region targets on the Settings sheet is named RegionTargets. Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.Workbook(File.Contents(SourceFile)),
RegionTargets = Source{[Item="RegionTargets",Kind="DefinedName"]}[Data]
in
RegionTargets
Result: The RegionTargets range with East (400), West (350), and South (300), with the Region and Q1 Target headers still in the first row

Here, the Kind for a named range is DefinedName, so that’s what goes in the lookup. A named range is read like a sheet, not like a table, so its headers stay in row 1 when useHeaders isn’t set.
To get proper headers, set useHeaders to true (as in Example 3), or add a Table.PromoteHeaders step (as in Example 4).
Example 7: List Only the Visible Sheets
Sometimes a workbook has hidden sheets with old data or helper calculations, and you don’t want them in your list.
Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.Workbook(File.Contents(SourceFile)),
#"Visible Sheets" = Table.SelectRows(Source,each [Kind]="Sheet" and [Hidden]=false)
in
#"Visible Sheets"
Result: A list with five sheets: Jan 2026, Feb 2026, Mar 2026, Products, and Settings

Here, the Table.SelectRows function keeps only the rows where the Kind is Sheet and Hidden is FALSE. That removes the hidden Dec 2025 sheet, along with the Products table and the RegionTargets named range, which aren’t sheets.
You can filter this list on any column, the same way you’d filter a regular table. The next example uses that to pick only the month sheets.
Follow along with the example file
Excel.Workbook Function Examples.zip
Example 8: Combine All Month Sheets into One Table
This is where Excel.Workbook really helps. You have one sheet per month in the same layout, and you want all the orders in one table, with a column that tells you which month each order came from.
Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.Workbook(File.Contents(SourceFile),true),
#"Month Sheets" = Table.SelectRows(Source,each [Kind]="Sheet" and Text.EndsWith([Name],"2026")),
#"Kept Columns" = Table.SelectColumns(#"Month Sheets",{"Name","Data"}),
#"Renamed Columns" = Table.RenameColumns(#"Kept Columns",{{"Name","Month"}}),
#"Expanded Data" = Table.ExpandTableColumn(#"Renamed Columns","Data",{"Order ID","Order Date","Product","Units","Amount"}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Data",{{"Month",type text},{"Order ID",type text},{"Order Date",type date},{"Product",type text},{"Units",Int64.Type},{"Amount",type number}})
in
#"Changed Type"
Result: One table with 11 orders (four from January, three from February, and four from March) and a Month column showing which sheet each row came from

Here’s what each step does:
- Source reads the workbook with useHeaders set to
true, so each sheet’s table comes with its headers. - Month Sheets keeps the sheets whose name ends with 2026, which picks up the three month sheets and skips Products, Settings, and the hidden Dec 2025 sheet. Filtering on Name is safe here because, for sheets, Name and Item hold the same text (as Example 1 shows).
- Kept Columns and Renamed Columns keep only the Name and Data columns and rename Name to Month.
- Expanded Data uses the Table.ExpandTableColumn function to open up each sheet’s table and stack all the rows, with the Month value repeated on every row.
- Changed Type sets the data types, because the expanded columns come in without any type.
You could also stack the sheets with the Table.Combine function, but it only takes the tables, so you’d lose the Month column. Expanding the Data column keeps each sheet’s name next to its rows.
This keeps working as the workbook grows. Add an Apr 2026 sheet in the same layout, refresh the query, and its orders show up with no change to the code.
If you want to do this with clicks instead of code, see my guide on how to combine data from multiple worksheets with Power Query.
Example 9: Combine the Same Sheet from Every File in a Folder
This last one is a very common task. Each region sends you its own Excel file, all with the same Sales sheet, and you want one table with all of it.
Below is what the Folder.Files function returns for the Regional Sales folder: one row per file, with the file’s content in the Content column. It’s the same function you’d use to list file names in a folder.

Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Folder.Files(SalesFolder),
#"Excel Files" = Table.SelectRows(Source,each Text.Lower([Extension])=".xlsx" and not Text.StartsWith([Name],"~$")),
#"Added Region" = Table.AddColumn(#"Excel Files","Region",each Text.BeforeDelimiter([Name],".")),
#"Added Sales" = Table.AddColumn(#"Added Region","Sales",each Excel.Workbook([Content],true){[Item="Sales",Kind="Sheet"]}[Data]),
#"Kept Columns" = Table.SelectColumns(#"Added Sales",{"Region","Sales"}),
#"Expanded Sales" = Table.ExpandTableColumn(#"Kept Columns","Sales",{"Order ID","Product","Units","Amount"}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Sales",{{"Region",type text},{"Order ID",type text},{"Product",type text},{"Units",Int64.Type},{"Amount",type number}})
in
#"Changed Type"
Result: One table with eight orders from the three files, with a Region column showing East, South, or West for each row

Here, Excel.Workbook runs once for every file. In the Added Sales step, Excel.Workbook([Content],true) reads each file’s content from the Content column, and {[Item="Sales",Kind="Sheet"]}[Data] picks its Sales sheet.
The Excel Files step makes sure only Excel files go through that. The Text.Lower function catches files saved as .XLSX, and skipping names that start with ~$ drops the temporary lock file Excel creates while one of the files is open.
The Added Region step uses the Text.BeforeDelimiter function to take the file name before the dot, so East.xlsx becomes East. Then the Sales tables are expanded and the types are set, just like in Example 8.
To add a new region, drop its file into the folder and refresh. For a click-based way to do the same thing, see how to combine data from multiple workbooks in Power Query.
Other Excel Articles You May Also Like:
- Web.Contents Function in Power Query M
- Csv.Document Function in Power Query M
- Table.ColumnNames – Use Table.ColumnNames in Power Query M to list a table’s column names.
- Sql.Database – Use Sql.Database in Power Query M to connect to a SQL Server database.
- Table.SelectColumns – Use Table.SelectColumns in Power Query M to keep only the columns you need.
- Table.NestedJoin – Use Table.NestedJoin in Power Query M to merge two tables.
- Json.Document – Use Json.Document in Power Query M to parse JSON text.
- List.Combine – Use List.Combine in Power Query M to join lists into one.