Excel Parameters in Power Query
Overview
For certain modelling situations, you may want to pass a collection of parameters from Excel to Power Query. In this article, we explain how to do this, passing the given parameter in, as a variable:
Extracting orders of particular date
Suppose you have the following Order data. You would like a single cell in Excel, which holds a date, to be passed into Power Query, so that when the query is refreshed, it updates to show only those orders of the passed in date.
![](images/excel-parameters-pq-1.png)
The following steps explain how to do this:
Steps
1. Set up a Parameter as a table
- Create a single cell table that contains the date of the orders to extract.
![](images/excel-parameters-pq-2.png)
- Click in the table ➔ click the From Table / Range icon under the Data tab, in Excel
![](images/excel-parameters-pq-3.png)
The table should load into Power Query as a single celled table. The date cannot be used in this tabular format, so needs to be drilled down on. To do this:
- Right click the cell, and choose Drill down
![](images/excel-parameters-pq-4.png)
Now only the actual value should be returned, as a scalar value, like so:
![](images/excel-parameters-pq-5.png)
Now that this is a value (the scalar value, can be directly used inside another query.
2. Extract the required data for any random date
Next, create a query to extract the required data from the database.
- Load the underlying data into the Query Editor
- Apply a filter from the drop-down box, for any random date, as shown:
![](images/excel-parameters-pq-6.png)
This will create a query step that references the date selected above, with the following code.
![](images/excel-parameters-pq-7.png)
3. Link to the Parameter table
- Now, replace the hardcoded date in the code above, with the name of the Parameter query created before
![](images/excel-parameters-pq-8.png)
- Select Close & Load, so the query loads to the original spreadsheet.
![](images/excel-parameters-pq-9.png)
- To check that everything works, change the date in the Parameter table, and refresh the query table again.
The query should return orders with a date that match the parameter table!
![](images/excel-parameters-pq-10.png)
Feedback
Submit and view feedback