Skip to content

Importing the first sheet in a workbook

Sometimes only the first sheet of a workbook is wanted, such as a workbook where each month’s data goes on a new sheet at the front. A query that picks the sheet by name breaks when the name changes, so this page picks it by position instead.

The method has two parts:

  • Connect to the workbook, which gives a list of its sheets.
  • Change the query so that it always takes the first item in that list, whatever its name.

In this example, each month has its own sheet, and the latest month, Jun, is the first tab:

A workbook whose tabs run Jun, May, Apr, Mar, Feb, Jan and Sheet6, with order data on the Jun sheet

The query should return the first sheet’s contents, even after a new month’s sheet is added at the front.

  • On Excel’s Data tab, choose Get Data ➔ From File ➔ From Workbook.
  • Browse to the workbook and click Import.
  • In the Navigator, click Transform Data without selecting a sheet.

The Navigator listing the workbook’s sheets in alphabetical order, with no item selected

The query’s Source step 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, Kind and Hidden

The Navigator sorts the sheets by name, but the Source step lists them in the order of the workbook’s tabs, so its first row is the first tab.

  • Click the fx button beside the formula bar, and enter this formula as the query’s second step:
=Source{0}[Data]

{0} picks the first row of Source, because Power Query counts rows from zero, and [Data] takes the table held in that row’s Data column. The step therefore always returns the first sheet, whatever it is called:

The contents of the Jun sheet, with Order No, Order Qty, Unit Price and Total columns