Add new table from external source using existing connection - excel

I have an Excel 2013 workbook where I have created multiple tabs with each tab showing the results from a different view from an external database.
I did this by clicking on DATA->OTHER DATA SOURCES where I then setup a connection and selected all of the different views I wanted to see in the workbook. Once I selected the views the results were automatically populated in a new tab in the worksheet.
Now, I want to add another view as a tab in the workbook using the same connection, but cannot find out how to do this and the only way I can do it at the moment is to add the table using a different connection.
How can I do this?

My understanding is that you can't use a connection twice. The connection is tied to the specific SQL statement or table/view name. If you create a connection on one page, and you create a new query on another page using Data - Get External Data - Existing Connections, Excel copies the existing connection rather than running two external data queries through it.
Excel's Connection object has a file associated with it, usually in My Documents\My Data Sources. Even if you select a specific table, that file only contains the connection to the database, not the table/view. So Connections don't appear to be table specific, but they contain other objects and tie them to a specific table.
Every Connection object has an ODBCConnection property and an OLEDBConnection property that point to their respective objects. These objects have a CommandText property for the table name or SQL statement. There's only one of these per Connection, which is why I'm pretty sure that you can't use one Connection for two external data queries.

My method is:
(With your Excel Workbook open) Select Data Tab > Queries & Connections, the "Queries & Connections" pane opens to the right.
Right-Click any of the existing queries
Select Edit, opening Power Query
Select Home tab > Recent Sources (in the New Query group)
Select the source you want to pull more data from
The Navigator populates - the screen that displays when you first connect to a data source. From here you can select one or more tables from the source and add them to your data model.
I know its a late answer - but I hope this helps!

Related

Delete Power Query steps after loading to Power Pivot data model

I need to delete query steps after loading the data into model. The reason is to hide the sources, protect our know-how, or maybe I'm just not very proud of what I've done ;).
But when I delete PQ connections or change "Load To" option, also the tables disappear from data model and pivot table becomes unresponsive. It's also not possible to modify or delete the connection created in Power Query from Power Pivot window, or even view table properties.
I could use Review > Protect Workbook > Protect Structure to disable viewing and editing queries / connections, but the steps are still visible, and the user cannot modify the workbook; even pivot table drill-through function doesn't work as it needs to create a new sheet to show data rows.
If you need to remove the query steps, then you have to store the data within the Excel file (since a query is just a set of instructions for how to connect to the data and transform it).
What you can do is create a query, load it to a table in an Excel sheet and then delete the query, leaving a static table. You can then create a pivot table using this static table as the source and it should function normally (though you obviously won't be able to refresh the data). I.e. don't create a data model until you've loaded your data and removed the query.

Power Query/ Excel - automated query refresh

I have introduced several Excel files in the company, which use Power Query to consolidate different Excel files and prepare them accordingly. The structure is as follows:
1st file:
- Query from Access
- Querys from 3 Excel files
2.-5.Datei:
Various Excel files.
Some of these files are updated daily with new records.
That means I have to daily in the excel files with the queries and these update.
Is it possible to outsource this somehow?
Sharepoint, server?
What ideas do you have?
Except a VBA macro which opens and refreshes the data accordingly?
Best regards
If you have one file with Power Query that get data from multiple files with daily refreshed data without any Power Query in them then:
In file with Power Query when you add result of Power Query to sheet you will get connection.
You can customize this connection to refresh on workbook opening or every N minutes.
Is this is what you want ?
Here:
http://www.excel2013.info/power-query/automatic-update/
you can see in "Refresh the connection" section how to customize connection.
Refresh the connection
Because your data is in a table, your table is link to your source of data. When you will receive a new csv file with the same name, in the same folder, you just have to refresh the query to update your workbook or you can refresh automatically your table when you open your workbook. To do that, you have go to the menu Data > Connections
In the dialog box Workbook connections, you select one of the connections of your workbooks (here there is only one connection) and you click on Properties …
Select the option Refresh data when opening the file
Don’t forget to save and close your file.
If you have multiple files with Power Query and one file get data from another files results of Power Query then you can schedule some code to refresh connections. You can create Console App (C# language), add some library to work with Excel, get target files, open its workbook, refresh connections.
Like here:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/b288098d-d4e8-4845-ae3f-38ad235e22aa/how-to-execute-a-quotrefresh-allquot-for-excel-programmatically-in-c?forum=csharpgeneral
Open Excel File, Refresh Query and Save C#
This way multiple files with Power Query will have always updated results of Power Query.
And your one main file with Power Query that get data from results of Power Query from this multiple files will have always updated data.

Excel internal database connection

I built a data entry UserForm to populate a worksheet that will serve as the raw database. The raw data requires further manipulation and analysis in order to be reported, so I set up a database connection using Get External Data>From Microsoft Query>Excel Files, pointed it to the file I was already working in, selected the fields I wanted and performed basic functions on those I wanted aggregated. This creates an Excel table where I then use formulas that to complete the analysis. It works great for me; I can add entries to the database, Refresh the summary table, the new entries are added and the formulas populate automatically.
The problem is that no one else can refresh the table because it's looking locally for the file. The connection string is:
DSN=Excel Files;DBQ=C:\Users\MyName\Desktop\Folder 1\Results.xlsm;DefaultDir=C:\Users\MyName\Desktop\Folder 1;DriverId=1046;MaxBufferSize=2048;PageTimeout=5;
I have a very basic understanding of the database connections, but I need this file to be as automated as possible by request of my colleague. Can I fix the connection string so that the file is "flexible" and can be refreshed on any computer? Is this the best solution? If not, what else can I do that does not involve downloading additional plugins or 3rd party add-ins?
If what you need is a file containing the raw data (a Database) AND one or more excel files connected to it that pick up the data from the database and work with this data, you need to split the two things. You can do the database with an access file located on a shared directory with an appropriate table and you can reproduce the user form in this file so the insertion of the data will be made in this file. Then you connect one or more excel files (using connection Mode = Share Deny None, so you can update the data and at the same time work with them from the excel files), the data will be imported in the files in tables and here you do all the proessing you need.
If one file is enough for you (you don't need to have a database with the row data separated and you don't need to use the file from different location simultaneously) and all the problem is that if the file is opened from a different location from the one specifyed in the connection string it does not work...well in this case (that seems the case) i don't know why to use a connection to the same file.
If what you need is a table for work with, just create it selecting the range with the data you already have inserted (Create a table - quick start guide) and then when you add data through the form instead of adding them in a "normal" row, add them to a new row of the table with something like WorkSheets("name").ListObjects("table_name").ListRows.Add and add the data in the new table row.

Change data source of a list table in Excel 2010

Is there a way to change the data source of a list table in Excel? It's easy to change the data source of a pivot table but the only way I have found to change the data source of a list table is to delete the table and start again.
Just to be clear, what I mean by a list table is what you get when you set up a connection to a table or query in Access (for example) and then click on "Existing Connections" under the Data tab.
I would prefer a method using the usual user interface but if there is a method that works only in VBA, that would be fine.
You can do it from the Excel interface without VBA.
Under the Data tab, click on Connections.
From the Workbook Connections dialog, click Properties.
From the Connection Properties dialog, click Definition.
Browse for a connection file and then select a table.
That's it.
If your data source is inside Excel on another sheet and you're using OLE DB Query, you might find changing the data source impossible (which was the case with me).
To change the data source in this instance, you need to click on Resize Table under the Table Design tab in Excel, as can be seen below:
When you click on this, you are able to change the range of your query, as can be seen below:

Excel 2010: Replace a table by an external connection without impacting other sheets

I have a big workbook with a lot of data. In one sheet I have a table. This table is used for many Pivot tables used in other sheets, which are also used in other sheets.
The data for the table was copied manually regularly. I now have a external connection to import automatically the data but I'd like to avoid impacting other sheets.
How can I use my external connection without losing my table?
Thank you for your help
This might be a helpful workaround. I have successfully done this but it may require a bit of rework and not be the exact answer you expect. (I am using Excel 2010).
The reason for a workaround is I assume this is for a regular table (not a pivot table) as the source table. Unfortunately, I don't believe the switching connection options work for regular tables in Excel 2010.
Recreate a new table just below the other in the same worksheet by going to the Data tab > Get External Data > Existing Connections
Select your data connection (assuming it has been created) then select how you want to view the data. ie: Table
Place in your existing worksheet. Use your old table as a reference to reconnect all the connections to your other sheets, then delete the old table.
At this point, I find it easier to rebuild/copy those existing links to the new table with external data.
The good news: If your source table is a pivot table or pivot chart with an existing connection, you can easily change the table to have an external data connection (and switch between data connections).
For a pivot table with an existing connection you wish to change, select a cell in the table. In the ribbon above in 'PivotTable Tools' > Options tab > Change Data Source, you will be able to select this and reconnect to another source under 'Choose connection'.
For a pivot table with static data to introduce a new connection, I would suggest a similar workaround above.
I hope this works for you.
I'm going through this too. I've done some testing, and this is the approach I am going to take.
Save copy of file (just in case!)
Create a new sheet, and create link to your database, and have it entered as a table on this new sheet
Make sure your old table (manually entered) matches the same layout as the table with the data you are connecting to (same column order and column names)
For each pivot table, change the source to the new table (it should keep all of your setup the same if the columns are labeled the same)
Do a find and replace to change all formula referencing to the new table name.
Change any code in VBA that references the old tables
This should result in the least issues while making the changes. Just don't forget the first step!
If both connections/query are SQL or PostgreSQL, you can simply copy the query code from the new query to the old query. Then you do not even have to replace anything. "Edit" - "Advanced editor"

Resources