Pass parameter from a cell in excel workbook to SQL Query - excel

Please note I have found solutions to this in Excel 2007, 2010, 2013 etc but nothing that relates directly to 2016.
I bring in a query to Excel by using Data / Get Data / From Database / From SQL Server Database.
What I want to do is restrict 1 column in the data it retrieves to a specific value.
In my exact example there is a date column and I want a cell in the spreadsheet to pass the date value to filter the returned query data.

For this application, I don't think you need to actually pass the date as a parameter to your query. You can just use the date from the cell as a filter after you've loaded your query into the Query Editor. As a result of query folding, Excel should automatically pass it into the WHERE clause of the native query it sends to the SQL Server Database.
If you don't know how to reference a cell value in the Query Editor, please see this question:
How can I reference a cell's value in a Power Query

Related

Excel Power Pivot / Data Model - passing a parameter from worksheet

I have a SQL query I am using for a workbook requiring multiple pivot views from the same dataset. Part of the query is looking at a declared value and based on that value it will either return one result or another, that declared value however needs to be a parameter that end users will input into the workbook.
Normally I would use the excel function to pull the data from the SQL server and then pass a parameter in the advanced query option using " Let Parameters = Excel.CurrentWorkbook()".. however the result set it too large and therefore I need to use Power Pivot.
I however for the life of me can find no help on how to pass a parameter from a cell in a worksheet to power pivot - is this possible, is there a VB script I can use to update the query, alternatively what other options are available other than having to get the end users to go into power pivot and edit the query in the properties each time?
As the variable is used in a computation, I am not using the parameter to filter the dataset and that seems to be the only advice I have been able to find. I am new to Power Pivot.
I came right by doing the following:
Add the SQL query in Power Query, as a data connection only. In the advanced query options, I added the required parameters.
I then selected the query and selected the option to load to Data Model.
Seems to be working.

Using value from Excel cell as filter in MS Power Query

I got an excel file which should use a query from an ms access file (which is a front end for a ms sql server)
But instead of receiving every entry I want to use a filter by a value that is in one of the excel cells.
So if in A1 is date 01.01.2000, I want to use this value to only show me all entries by that date
If do not need to use power query if there is an easier way to do it.
You can pass a value into power query using a table and have your original query reference that cell/table. More detail here: https://exceleratorbi.com.au/pass-excel-parameter-power-query/
check the sample file, fill the parameters as per your DataBase
https://docs.google.com/spreadsheets/d/1nhB710FEl_AfFQy6HwDmR8xhcWWuw91p/edit?usp=sharing&ouid=100599386090580961037&rtpof=true&sd=true

How to prevent excel from showing dates as number

I'm using excel to get data from an external SQL server table, using power query, in the query window it shows date/time fields normally, but in the excel sheet, it shows it as a number, even when I change the type and cast and make a refresh it transform it again as a number.

How do I pass parameters to my SQL statement?

How can I use parameters to create a dynamic SQL statement? I specified two parameters "DateStart" and "DateEnd" which I want to include in my Data source's SQL statement, but I don't know what the proper way to reference them is.  My aim is to have the users be able to adjust the parameter dates at the opening of the report.
For Example:
Select projectid,projectname,date,agent,count(*) from production Where
fromdate = '04/01/2020' and to date = '04/05/2020" Group by Projectid,
Projectname,date,agent
Now, dates filters will be added in Excel cells and based on inputs result will appear on the table.
Also, advise will that work in MS Office 2016 & O365 version as well.
Thank you in Advance!

How can I pass a list parameter to an ODBC query in Excel (Microsoft Query)

I'm having some trouble passing a particular type of parameter from an Excel cell value to an ODBC query. It's a DB2 database on an AS400 server, and I'm using the iSeries Access ODBC Driver from IBM.
Here is the query with hard-coded values:
SELECT STKB.BXPART, STKB.BXSTOK, STKB.BXQTOH, STKB.BXUNIT
FROM CMSDAT.STKB STKB
WHERE (STKB.BXPART In ('BAG024','BAG709'))
And the desired result:
What i would like to do is pass the list from an Excel value to the parameter. The query is modified like so:
SELECT STKB.BXPART, STKB.BXSTOK, STKB.BXQTOH, STKB.BXUNIT
FROM CMSDAT.STKB STKB
WHERE (STKB.BXPART In (?))
And the parameter is set to pull from a cell:
If I put one value in the cell, the query returns the results for that one value. If I try more than one item the query returns empty. I've tried the following values in the cell AA4:
('BAG024','BAG709')
(BAG024,BAG709)
'BAG024','BAG709'
BAG024,BAG709
Has anyone successfully used cell values for an 'in' parameter?
Thanks!

Resources