Skip to content

Combining workbook sheets

This page combines all the sheets of a workbook into a single table. The pattern has three problems to solve:

  1. The query has to pick up new sheets automatically when they are added.
  2. Each sheet has its own header row, and those rows must not appear in the combined data.
  3. The column that holds each sheet’s name has to keep working when sheets are added or their order changes.

In this example, a workbook holds order data, with one sheet per month and a spare sheet, Sheet6, at the end:

A workbook of order data with tabs Jun, May, Apr, Mar, Feb, Jan and Sheet6

  • Open a new workbook.
  • On the Data tab, choose Get Data ➔ From File ➔ From Workbook.

Excel’s Get Data menu open at From File, with From Workbook highlighted

  • Browse to the workbook, and in the Navigator click Transform Data without selecting a sheet.

The Navigator listing the workbook’s seven sheets, with no item selected

The query lists every sheet in the workbook, one per row:

The Source step, with a row for each sheet from Jun to Sheet6 and columns Name, Data, Item and Kind

Because the query lists whatever sheets the workbook holds, a sheet added later appears on the next refresh, which solves the first problem.

2. Use each sheet’s first row as headers

Section titled “2. Use each sheet’s first row as headers”
  • Edit the formula of the Source step so that its second argument is true instead of null:
= Excel.Workbook(
File.Contents("C:\....worksheets.xlsx"), true, true)

The second argument of Excel.Workbook says whether to use the first row of each sheet as its column headers. With it set to true, each sheet’s table arrives with its headers already promoted, so the header rows are not combined into the data, which solves the second problem.

  • Filter the Name column to keep the rows where it does not begin with Sheet, which removes Sheet6.

The Filter Rows dialog keeping rows where Name does not begin with Sheet

  • Remove every column except Name and Data:

The query reduced to the Name and Data columns, with a row for each month from Jun to Jan

  • Click the expand button in the Data column’s header, and keep all the columns ticked:

The expand menu on the Data column, with Order No, Order Qty, Unit Price and Total ticked

The sheets are now appended into one table, with no repeated header rows, and the Name column shows which sheet each row came from:

The combined table, with the Name column showing Jun beside each June order, followed by Order No, Order Qty, Unit Price and Total

  • Rename the Name column to something more meaningful, such as Month. The rename refers to the column by its name, so it keeps working whatever sheets the workbook holds and in whatever order, which solves the third problem.