Connecting different databases in Excel - excel

Let's say I have an Access database, "ADB", and an Excel workbook, "EWB".
ADB has a table called "ATable" which contains columns including a column called "A_ID"
EWB has a worksheet called "EWorksheet" which contains columns "E_ID" and "ECol"
Now, I want to know how I can create an Excel worksheet that combines ATable.A_ID from ADB and EWorksheet.ECol from EWB, where if A_ID = E_ID then return ECol.
So in SQL, it should look something like this:
SELECT ATable.A_ID, EWorksheet.ECol
FROM ADB.ATable, EWB.EWorksheet
WHERE ATable.A_ID = EWorksheet.ECol
Of course I want the data to be dynamic, so that data will be updated when refreshed.

You need something called PowerQuery, in Excel 2016 comes by default. In previous versions you will have to install it.
Once you have it, it´s pretty straightforward. Select a connection as seen below selecting an Access database or an Excel workbook.
Once you have both queries loaded in PowerQuery you need to merge them through the column you specified, and that will make the join for you.
What PowerQuery does is record a set of steps such as connecting to an Access database or merging 2 tables. Those steps are saved within the file, so when you click RefreshAll in Excel it will reproduce those same steps you specified and bring you the latest data.

Related

Excel - read data from ODBCbut paste values only

i have an excel document with conditional formatting and data validation lists and lookups.
The users populate this data in Excel.
I then read it into HANA DB and find any new records required to be enriched.
I would like then to be able to refresh the data in Excel with the data i have in HANA however when I go to import via ODBC I then get a table created.
Ideally, it would paste values back into Excel rather than creating a table object as this removed the formatting included originally
Are there ways around this?
Thank you
Create a hidden sheet where you can place your ODBC source table and write a VBA code that will copy and paste new records from ODBC connection to your user-friendly list. You may filter this enriched records via VBA or PowerQuery join or with something like index and match functions.

Excel format lost while populating thru SSIS

I have an formatted excel destination with one of the columns being a percentage and another being currency. I'm loading this excel with data from a sql table using SSIS. However the excel is not formatted after the load. What is happening?
I was able export two columns of information (percent and dollar value) to an Excel file (97-2003 format) from an SSIS package created in Visual Studio 2010. The data was sourced from a table on a server using SQL Server 2012.
Steps:
Created an Excel file containing a column called Percent and another called Cost. Both were formatted accordingly and are located in the first row.
Saved the file in a 97-2003 format and then closed it.
Created a table in a database and populated it with a couple of records.
create table test_export (
mypercent numeric(18,2),
mydollar numeric(18,2))
insert into test_export values (2.1, 50.00)
insert into test_export values (4.5, 120.00)
Opened Visual Studio 2010 and created a new SSIS package. Created an OLEDB connection to the database.
Under the Control Flow tab added a Data Flow Task and double-clicked on it after it was added. This should now highlight the Data Flow tab.
Add an OLE DB Source and point to the newly added database connection, under Data access mode select Table or View and then select the table created in step #3. Select the OK button.
Add an Excel Destination making certain to create a new Excel connection manager for it and point to the Sheet1$. Make certain to indicate that the first row contains headers. Select the OK button and connect the OLE DB Source task to the Excel Destination task below. Since only numbers are involved, there is no need to apply a Data Conversion task between the two. But in the Excel Destination task remember to select Mappings and connect from left to right which source columns match up with which destination columns.
In the Solution Explorer pane, right-click on the solution and select Properties from the drop-down menu. Open Configuration Properties on the left and the select Debugging under it. On the right under Debug Options, look for Run64BitRuntime and change it from True to False if you have not already done so. Select the OK button.
Run the SSIS package.
Stop the SSIS package when all of the tasks show green for completed.
Open the Excel file and it will now contain the values imported from the database table with the Excel percent and dollar formats preserved from step #1.
I ran these steps in a test and everything worked perfectly. If your formats are not being preserved, then you are likely leaving out a step.
Hope this helps and please indicate if it answered your question.
I had the same problem. What I did was:
apply conditional formatting on the column.
see attached picture
It is also important that you have in the first row, a model row, filled with numeric/text values, in order for the ssis to export the numbers as numbers and not as strings model row
If your template contains several rows before the place where ssis start to export the data, you might need to have more model rows. (I needed 4). This rows have to be the first rows in the document, regardless where you start the export.
You can hide the model rows

Link to pivot table from another excel file

Banging my head against the wall on this one and every option I try has a problem with what i am trying to achieve.
So I have a pivot table in excel that is connected to a database. What I want to be able to do is have a link in another excel sheet to that pivot table, so that it picks up any changes to it in terms of data. The reason I am doing this is because I am putting the excel file up on sharepoint, but if a user downloads it, it retains the connection to the SQL Database, and because they are not authenticated, it doesn't refresh. I need them to be able to do this because it will allow them to customise their pivot table as needed, and it will retain that when they next open it. But the original pivot table, connected to the datasource, won't be affected.
I have tried:
Copying Pivot Table: I have copied the pivot table and pasted it in a new excel file, and this retains the connection to the SQL Database so doesn't work.
Moving Worksheet: I have tried moving the whole worksheet to a new excel file and this does again retains the link to the SQL Database.
Creating connection to excel file: This connected to the excel file, but the pivot table is lost and it simply shows the data in standard excel format.
Slicers: I have looked at slicers but this won't work either, because it means if he makes a change it is reflected in the original pivot table.
Sharepoint: I have looked at excel services on sharepoint. Although I can get him to view the data on the online excel, again, if he downloads it it loses the connection.
I guess I could change the authentication settings on SQLServer so that rather than using windows authentication I create a password and then that password is retained as I copy the file. Because this would only allow access to the view in the SQL Database this would prevent any detrimental activity. However, what I would really like to do is just give a copy of the excel file that connects to the original pivot table (so that when this updates this data is reflected in the copy on refresh), but any changes in the copy (i.e. formatting etc) only affect the copy.
If anyone knows how to do this I would be most appreciative of your help.
I may said something incorrect here, so pardon my lack of knowledge, but with the option:
Creating connection to excel file: This connected to the excel file, but the pivot table is lost and it simply shows the data in
standard excel format.
If I understand correctly, Creating connection to excel file provides a copy of the database in an excel file with all the source data from the original pivottable, and if by "connected to the excel file" you mean that any changes to the original pivottable is updated in this connected file in the copy of the database.
Then adding a replica of the pivottable in this connected excel file pointing to the copy of the data would not solve the problem?
Am I missing something?

Has anyone achieved to use ODBC connection from Excel file into Powerpivot?

I have installed Powerpivot for Excel 2010. I don't have Access 2010 so I thought could I arrange the data in the similar manner as I would for a database.
I'm wanting to query an excel file that has rows of self-generated data into Powerpivot in order to perform simple pivot table. In a sense attempt to get an overview of information about a data set.
At the moment, I'm unable to get set up correctly the ODBC I'm hoping I need to accept an Excel file and to get PowerPivot to accept a database from an Excel file.
Edit: I come to understand that I need to set up a table correctly in Excel so that the ODBC works correctly. Does the picture I provided be right manner to set up a table or any other manner?
Has anyone attempted to do this and if so what would the steps be?
Thanks,
Peter.
Peter, I am working on the basis that your data is in a recognizable table on a worksheet (and that you are not interested in using the standard Excel import method through 'From Other Sources')
If you create the connection to the Excel file in a very particular way it is possible to then query it as if it were a database.
Create a Connection to the spreadsheet in question in Excel through Data>Connections>Add.
In the PowerPivot window on the Design tab click on existing connections and find the connection you just created. Select the connection and Open.
You need to name the connection and then you will be offered the normal import options. Select the sheet you want to get the table from (its actually not important which one you choose at this point).
Once the table has been imported you can re-enter the setup through the 'table properties' on the design tab and you will now be able to 'Switch to' the query editor at which point you can not only write SQL to query your DB but reference any other .xlsx you like.
Jacob
the easiest way is to use a linked table from the excel sheet which has the data - is there any reason why you have not considered this as an option?

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