I want to filter data from an external data source.
I have an Excel sheet coming from a MySQL data source ([IN]).
Now I want a new sheet [FILTERED] having data from the sheet [IN] filtered on some user parameteres defined in sheet [PARAM]: {appointmentDay} and {idSite}
Ideally the sheet [FILTERED] should be updated automatically if the filters {appointmentDay} and {idSite} would change.
I suppose there should be a very easy solution, but unfortunately I don't find anything going into this direction.
I found a solution here:
How to use parameterized query in Excel using column as parameter?
In short:
1) you create a data source using "Microsoft Query"
2) in the where you use ? as placeholder for parameters
3) in the connection properties you define where to look for the paramters
Related
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.
So in Excel 2016, they have this neat tool called Power Query, basically a glorified excel table. Every table has steps in it for filtering, removing columns, etc... The first step is the source step, to assign a connection string basically to retrieve data, normally this source just points back to the query which created it.
Anyways, I'm trying in VBA to dynamically change the source of these power queries, anyone have any ideas?
I tried using the whole connections vibe, but was unsuccessful.
You can access the query through ActiveWorkbook.Item. You can then modify the Formula property. You can find the documentation on these objects here.
Please note that the Power Query object model was only added to VBA in Excel 2016 and cannot be accessed in prior versions.
The queries can be accessed via the Queries collection in a Workbook object. The relevant property for the source is Formula.
Example code:
ActiveWorkbook.Queries.Item("MyQuery").Formula = "[Insert actual M formula here]"
Many years later, but I'm adding a different solution for those, like me, still stuck with Excel 2013. As stated by #Alejandro in his response, Power Query was only added to the object model in Excel 2016.
If you are using an older version of Excel, you can use a cell-based solution similar to the one talked about here for relative source paths:
https://techcommunity.microsoft.com/t5/excel/power-query-source-from-relative-paths/m-p/206150
Basically have a cell some where in your workbook that contains your query's source. Name that cell, using standard Excel names. In the example below, I've named the cell SourceFileName, and I'm trying to load an Excel file to PowerQuery. The full name of the source Excel file (including path) is in SourceFileName . You can then access the contents of that cell via Power Query:
<previous M code>
sourceFileName= Excel.CurrentWorkbook(){[Name="SourceFileName"]}[Content]{0}[Column1],
Source = Excel.Workbook(File.Contents(sourceFileName ), null, true),
<rest of M code>
If you make a data connection to another Excel file or an Access table it will import that data into excel as a Table. This is great! But when I do the same with "From Text" and choose a CSV, it loads no problem, but it loads as a RANGE not a TABLE. This is highly frustrating as I NEED it to be in the table format so that I can take advantage of the dynamic column names.
Am I missing a tickbox somewhere? I'm not opposed to using VBA but it really seems odd that Excel can't do CSV to Table so I'm hoping for a native solution.
I should mention that if it's a VBA solution, it CANT break the workbook. So if I'm doing something like:
=SUMIFS(CSVDATA[SalesDollars], CSVDATA[RepName], "BOB")
It will still work after refreshing.
So you can get around the 'data connection' not creating a table by downloading the MS Excel 2010 plugin (from Microsoft) called Power Query. It's free and is a default feature in MS Excel 2013.
It will allow you to choose to create a Power Query Table from External Data >> From File >> From CSV
Upon doing this, it will create a named table for you and a Power Query object attached to the table. You can use the table itself the same way you normally would - with the Columns as references for formulas.
For instance, the default table that I just created using the steps above was auto-named: Table_ExternalData_1
I can then select it using the normal method in formulas:
=Table_ExternalData_1[Column2]
etc...
Hope that helps.
I have an Excel spreadsheet like this:
Where the Student Name, Student ID and Classification are, I would like to fill that with the results from a SQL Server view. The columns to the right (Capstone, Milestone 2, Milestone 1, Benchmark, Semester Grade, Notes) will remain blank until the instructor fills them in later. These columns will not be written back to the database but will be saved, with the data that is loaded from the database, into the first three columns in it's Excel spreadsheet format.
Question 1: Is there a way to simply "embed" the data that is coming from the view?
Question 2: If not, can you provide a link to an example using a macro to read records and insert them (moving lower rows down with each new record)?
TIA
On the Data tab in Excel you can select "From Other Sources" icon from the "Get External Data" group to pull your student data from a SQL Server view.
That will give you the "embedded" data, until you decide to Refresh your connection and retrieve updated data from the view.
EDIT:
Use the CopyFromRecordset method for Range objects. Here is the link that provides working examples for what you are trying to accopmlish, without the range being being pushed to the side. Entries #3 and #11 provide the VBA examples.
http://www.xtremevbtalk.com/showthread.php?t=217783
You will need to use VBA to create an ADO connection, recordset, command, and parameter.
Dim adostudent as ADODB. (...) ^ use the above
Then, assign a named range to the areas that you would like to drop the information
StudentRow
Then, use a Do Until and an iterator and do until.eof and .movenext to drop the values from the recordset into the range.
irow = 10 'insert the header row # + 1here
Do Until adostudent.EOF = True
with adostudent
StudentRow(irow,1).value =.Fields("Student Name").value
...
...
.movenext
irow = irow + 1
loop
You can use the Data->Get External Data->From Other sources->From SQL feature in Excel.
Or use my Add-In:
http://blog.tkacprow.pl/excel-sql-add-in-free/
I have a table with 105 columns and around 300 rows in Sheet 1. I need in Sheet 2 a reduced version of the same table, filtered by some column values (not the first column).
I've looked at Pivot Tables but it seems that I can not get the same tabular structure. I have tried with Advanced Filter and I get an error:
"The extract range has a missing or illegal field name".
Could you help?
Microsoft's PowerQuery addin supports this. One of its many sources can be Excel Data-From Table.
I have discovered that one needs to run Advanced Filter from the destination sheet, in an unused place (best over the intended destination, not on it or below it).
Thanks
You can use the add-in for table-valued functions I developed to make any operations (including filtering, partitioning, aggregation, distribution etc.) on data tables in Excel.
Each table (ListObject in Excel) is an input or output parameter for a table-valued function. You can for example feed three tables as input parameters to a table function which generates some resultant tables.