I have a SQL query with date parameters. I would like to use PowerQuery to run this…
- User
I have a SQL query with date parameters. I would like to use PowerQuery to run this query. The parameters will be entered by the user into cells in a worksheet. I would like to pass these parameters to the SQL query in Excel without losing query folding in PowerQuery. Is this possible?
Assistant
Yes, it is possible to pass date parameters from Excel cells to a SQL query in PowerQuery while preserving query folding. Here are the steps to achieve this:
- In Excel, create a worksheet with the following items:
- Cells to hold the date parameters, named "StartDate" and "EndDate" for example.
- A button to run the query, named "RunQuery" for example.
- In PowerQuery, create a new query and enter the SQL query with placeholders for the date parameters. For example:
sqlSELECT * FROM MyTable WHERE DateField >= {StartDate} AND DateField <= {EndDate}-
In the PowerQuery editor, click on the "Transform data" button to open the query editor.
-
In the query editor, click on the "Parameters" tab and create two new parameters, named "StartDate" and "EndDate" for example.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.