I've got 2 connections in a worksheet, querying an.accdb. How can I get an inner join on them within Excel?
Restrictions:
One of the existing connections returns a crosstab query. Crosstab queries cannot be used as subqueries in Access directly within an SQL string (the TRANSFORM keyword cannot be used after the FROM keyword). The crosstab must be saved as a new querydef first, and then the querydef is used as an alias
Both connection strings have WHERE criteria that change dynamically and are generated on-the-fly, hence it's not practical to open up the .accdb and change a crosstab querydef constantly especially in a multiuser environment
Hence I stress I want the join to be done within Excel. Since all the required data gets pulled in and stored locally in the spreadsheet after a Refresh All, surely we have all we need to perform a join in Excel...
Related
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.
My Excel applications exports data (6 columns by 300+ rows) to Access DB once a minute.
After exporting, I try to import two sets of older values from Access to Excel.
The primary query is:
SELECT qryStDevPct.StDevPct, atblExcelIntraday.ValueClose
FROM atblExcelIntraday
LEFT JOIN qryStDevPct
ON atblExcelIntraday.SecurityID = qryStDevPct.SecurityID
WHERE atblExcelIntraday.RecordDate Between #2022-05-04 13:55:59# And #2022-05-04 13:54:59#
ORDER BY atblExcelIntraday.Ticker;
The internal Access qryStDevPct is:
SELECT atblExcelIntraday.SecurityID,
Avg(atblExcelIntraday.ValueClose) AS AvgP,
StDev(atblExcelIntraday.ValueClose) AS STD,
[STD]/[AvgP] AS StDevPct
FROM atblExcelIntraday
INNER JOIN atblSecuritiesOpenPriceDaily
ON atblExcelIntraday.SecurityID = atblSecuritiesOpenPriceDaily.SecurityID
GROUP BY atblExcelIntraday.SecurityID;
The Price data from table always imports correctly, but StDevPct is either 0 or 1 30% of the time.
I can easily refresh it by doing manual "Data Refresh", but neither .Calculate, nor .QueryTables("qryPriceDB_1").Refresh work.
I could split it it two separate queries, but aside from programming it will take more time on the Excel end, and I'm trying to keep my main procedure to under 1,500 msec.
Please advise.
In Excel 2021, what exactly is a "data connection", "query" and "domain source name"?
Let's say I have a Workbook "Manahil_Customer_Database.xlsm" in which I have a sheet "sht_Customer_Cities" that has a table "tbl_Customer_Cities". In a new sheet "sht_Report" I want to run two queries using one connection via MS Query. Now when I go through the MS Query route I get one Domain Name Source File "Manahil_Customer_Database.dsn" and one MS Query file "Customer_Countries_Cities.dqy" and one Connection file "Customer_Countries_Cities.odc".
However when I look at the "Queries & Connections" it says 0 Queries and 1 Connection named "Customer_Countries_Cities". I want to be able to establish a single Data Connection via MS Query from the "sht_Report" to the Workbook "Manahil_Customer_Database.xlsm" and than run multiple queries using the same connection.
Power Query replaced MS:Query from Excel 2016 onwards. The objects and panes you are describing relate to Power Query, not MS:Query.
Power Query is far more functional, reliable, flexible and performant than MS:Query.
For example depending on your exact requirement, you might create a base query that gathers all the required data, then refer to that base query in Reference queries that filter the output needed for each destination table.
Here's a starting point for Power Query:
https://support.microsoft.com/en-us/office/about-power-query-in-excel-7104fbee-9e62-4cb9-a02e-5bfb1a6c536a
Power Query is a MS tool that assists you on your ETL tasks.
As read in a previous answer, it is based on M language.
To be able to import / modify / connect your data, the command is:
DATA / GET DATA and select your input
Check this link for a quick introduction:
https://learn.microsoft.com/en-us/power-query/power-query-what-is-power-query
If I understand the situation correctly, you are working internally, within a single excel file. Data connections, queries, and domain sources, are all used to associate externally.
Internally I would think you could use a pivot-table and/or a slicer.
If you provide additional details on what specifically you are trying to do, a better answer could be provided.
Some additional reading below may help further:
Power Query Help
Data Connections
Queries
External Links
Fairly new to power queries and finding my feet largely by trial and error.
I have build a master query returning ~ 2000 rows of data covering different regions. I want to create sub reports on different tabs for each region. I can easily do this by copying the original table and applying a filter on region for each new query. As my s/s is already 10mb, I am trying to do this is as efficiently as possible in terms of performance. I understand I can do this also by creating a "reference only" to the master query instead of duplicating and filtering master query (so creating 10 versions of master query with different filters).
I have been trying to do this via Query / Reference menu but not sure if I end up with a "connection only" query as it doesn't say it in the Queries panel on the right.
Anyway, I guess the questions are:
1. What is the difference between queries and "connection only" queries (especially with regard to performance / spreadsheet size)?
2. When is best to use "connection only" query?
3. How to create "connection only" query (ideally via menu not code) and how to check if a query is connection only?
Connection only signifies that the data is not being materialised anywhere. It may still be referenced by other queries, but the data isn't being loaded to a worksheet table or to the data model.
You can control the behaviour of queries with the Load To dialog, invoked by Close and Load To from the Query Editor, or right click > Load To from the Workbook Queries pane.
Connection only queries reduce workbook size - good rule of thumb is not to materialise any queries unless you really need to. In your example, it looks like you want to materialise each regional query, but unless you also need a master table of all regions, then your 'master' query may be connection only.
In performance and size terms, it makes more sense to only have your master query, loaded to the data model, with a regional slicer on your report...
I have a need to change the SQL of a query saved in Access from Excel and it must use late binding.
Specifically I'm building SQL strings in Excel VBA featuring a number of parameters provided by the user in Excel and querying the database via an ADODB connection. I have constructed core queries in the database which do most of the work so I can keep my SQL strings and the amount of data returned light on the Excel end.
Mostly this works fine but some of those core queries rely on other queries nested several levels deep, and some of the parameters I need to supply are around data in those parent queries. So, I'm thinking I need to temporarily amend the SQL of those parent queries before running my main code (unless anyone has another idea?). I know how to change the SQL for a queryDef in Access, but not how to get to the queryDefs from Excel.
So TL:DR - how can I get a handle on the queryDefs in an Access accdb from Excel?
Thanks.
Here is a late bound example
Dim db As Object
Dim qdef as Object
Set db = CreateObject("DAO.DBEngine.120").OpenDatabase("path to db")
set qdef = db.QueryDefs("query name")