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 maintaining query folding. Here's how you can do it:
- In Excel, create a worksheet with the cells where the date parameters will be entered.
- In PowerQuery, click on the "Get Data" button and select "From SQL Server."
- Enter the server name, database name, and table name for the SQL query.
- Click on "Advanced Editor" and paste the SQL query into the editor, replacing the date parameters with placeholders. For example:
SELECT * FROM MyTable WHERE MyDateColumn >= #datetimeparameter# AND MyDateColumn <= #datetimeparameter2#- Click "OK" to close the Advanced Editor and return to the PowerQuery Editor.
- Click on the "Transform Data" button to open the Query Settings window.
- Under "Parameters," click "Add Parameter."
- In the "Name" field, enter the name of the first date parameter (e.g., "datetimeparameter").
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.