Skip to content

Excel Parameters in Power Query

Some models need a value chosen in the workbook, such as a date or a region, to control what a query returns. This page shows how to pass a value from an Excel cell into Power Query, where it is used as a variable inside another query.

The source is a table of orders, with an order date, an order number, a quantity and a unit price on each row. The aim is to type a date into one cell in Excel and have the query return only the orders placed on that date whenever it is refreshed.

An Excel table of orders with the columns Order Date, Order Number, Order Quantity and Unit Price, where every row shown is dated 29/12/2010

  • Create a table with one column and one row, which holds the date of the orders to return.

A one-cell Excel table with the header Date and the value 03/01/2011

  • Click inside the table, and then click From Table/Range on Excel’s Data tab.

Excel’s Data tab, with From Table/Range highlighted in the Get & Transform Data group

The table opens in the Power Query Editor as a table with a single cell. A filter cannot compare a column with a table, so the date has to be taken out of it:

  • Right-click the cell and choose Drill Down.

The one-cell Date table in the Power Query Editor, with the right-click menu open and Drill Down highlighted

The query now returns the date on its own, as a single value rather than a table.

The Power Query Editor showing the single value 03/01/2011 under the formula bar

Because the query returns a single value, its name can be used directly inside another query. In this example the query is named Parameter.

Next, build the query that returns the orders.

  • Load the order data into the Power Query Editor.
  • Open the drop-down on the Order Date column and filter it on any one date.

The Order Date filter drop-down in the Power Query Editor, with only 02/01/2011 ticked in the list of dates

Power Query adds a step that filters on the date chosen, which is written into the step’s code as a fixed value.

The formula bar showing Table.SelectRows with the condition [Order Date] = #date(2011, 1, 2), above the five orders dated 02/01/2011

  • In the formula bar, replace the fixed date with the name of the parameter query.

The Queries pane listing Parameter and Data, with a line linking Parameter to the formula bar, where the condition now reads = Parameter, and the table shows the four orders dated 03/01/2011

  • Choose Close & Load, so that the query loads to the worksheet.

The worksheet with the Date parameter table holding 03/01/2011 above the loaded table of the four orders on that date

  • To test it, change the date in the parameter table and refresh the query.

The loaded table now holds only the orders placed on the new date.

The same worksheet after the parameter is changed to 09/01/2014 and the query refreshed, showing only orders dated 09/01/2014