Combine WorkSheets using Power Query in Excel

Power Query can stack the data from every sheet into one table. Use From Workbook to combine the sheets of another file, or Excel.CurrentWorkbook to combine tables in the same file, including sheets you add later.

Other workbookGet Data → From File → From Workbook
Same workbookExcel.CurrentWorkbook()
RefreshPicks up new sheets automatically

Which method?

Method Use when
1. From Workbook The sheets are in a different file, such as a monthly report
2. Excel.CurrentWorkbook The sheets are in the workbook you’re working in, and more will be added

Both need the same columns, in any order, with the same headers on every sheet.

Method 1: Combine sheets from another workbook

  1. In a new workbook, go to Data → Get Data → From File → From Workbook and choose the file.
  2. In the Navigator, right-click the file name (not a sheet) → Transform Data.
  3. Keep only the Data column: right-click its header → Remove Other Columns.
  4. Click the expand icon in the Data header, untick Use original column name as prefix, OK.
  5. Home → Use First Row as Headers.
  6. Filter out the repeated header rows: open the filter on the first column and untick its header text.
  7. Close & Load.

Keep the Name column if you want to know which sheet each row came from. Rename it Sheet.

Method 2: Combine tables in the same workbook

Four sheets, Violet, Indigo, Blue and Green, hold marks for more than 40 students.

Four worksheets of student marks

Step 1: Make each sheet’s data a named table

Click in the data → Ctrl + T → OK. Then on Table Design, name it with a common prefix: tb_Violet, tb_Indigo, tb_Blue, tb_Green.

Create Table dialog
Naming the table on the Table Design tab
All tables listed in the Name Box

Step 2: Blank query

Data → Get Data → From Other Sources → Blank Query, and type in the formula bar:

= Excel.CurrentWorkbook()
Get Data, From Other Sources, Blank Query
Excel.CurrentWorkbook listing all tables

Step 3: Keep only the tb_ tables

Filter the Name column → Text Filters → Begins With → tb_.

Text Filters Begins With
Filter rows beginning with tb_

This filter is essential. The combined table you load back is also a table in this workbook. Without the filter, it would be included on the next refresh and the data would double each time.

Step 4: Expand and load

Click the expand icon on Content, untick the prefix option, OK. Rename Name to Group and the query to Marks, then Close & Load.

Expanding the Content column
Renamed query and headers
Consolidated data from four sheets

Step 5: Add sheets and refresh

Add a new sheet with a tb_ table, then right-click the result → Refresh.

Three new sheets added
Refresh appending the new sheets

Other ways

  • Excel 365: =VSTACK(tb_Violet,tb_Indigo,tb_Blue,tb_Green) stacks tables with a formula.
  • Many separate files in a folder: Get Data → From File → From Folder.
  • No Power Query: the merge Excel files tool or the combine worksheets macro.

Related

Last updated · Written by Ajay Anand, Microsoft Excel MVP