I have never used Power Query before so I'm not sure if what I'm asking is even possible. I want to find out a way in excel to dynamically import data from a website based on the value given in another cell, something like importhtml in google sheets. For example, here's what I created using google sheets:
If you notice,
the first column is an NPI number which is what I'd provide (copy and paste to the column in excel).
the second column is the url from where the data to is to be downloaded. The url number value is referenced to column A.
importHTML then imports the data and puts them in the column following URL.
So, is it possible to do something like this using Excel Power Query?
Although I used the regular url to pull down the data in html table format, I prefer to use JSON if possible. The only reason I didn't use JSON in google sheets is because I don't know how to. The URL for NPI lookup API is https://npiregistry.cms.hhs.gov/api?number= where we can enter any NPI number to lookup.
Yes, Power Query's Web.Contents function has a parameter for the URL - this can be an expression or a literal, or a concatenation of both. You can get a jump start on the syntax by using the "From Web" button (in Excel 2016+, this is (sadly) a bit buried under Data / New Query / From Other Sources) - this will generate the code including the Web.Contents function with a literal URL. Power Query will also look at the contents returned and wrap the appropriate function around Web.Contents e.g. Json.Document.
You could start from your existing Google Sheets file (they are also easy to consume using Get Data / From Web), and use Add Custom Column to paste in your Web.Contents code. You can insert a column reference to make the URL dynamic - using & for string concatenation.
Related
I'd like to create an Excel sheet, where in one column there is a link to a website
like this:
Link in column A where there is a MAC add in that url that changes from line to line rest of link is geraric. and it takes the info in the 2 lines marked with arrows and put into another cell.
This should be possible for multiple links in different rows from websites with the same structure.
How can I make the web query to be based on the link in the adjacent cell?
You can use Power Query to read the contents of a cell.
Then in Power Query, you can return the web contents of the URL like this:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Get Web Contents" = Xml.Tables(Web.Contents(Table.FirstValue(Source))),
in
#"Get Web Contents"
You will need to be mindful of the data your query returns, i.e. is it a single value, table, or otherwise?
Here is documentation on how to to load the results from Power Query back to your excel worksheet: https://support.microsoft.com/en-us/office/create-load-or-edit-a-query-in-excel-power-query-ca69e0f0-3db1-4493-900c-6279bef08df4
I sort of found out. just made a simple WEBSERVICE(A2) to the URL and it returns a string with all the data, now i just need to extract only the data i need.
I'm trying to search the website "capfriendly.com/players/" using a column of cells and import the "Cap Hit" value back into excel in the adjacent column for each.
I'm a complete beginner when it comes to programming, so I've mostly been trying to learn from previous questions such as this one: excel macro to search a website and extract results
I'm still pretty perplexed, especially with how to extract just the specific value I'm looking for. Any guidance would be greatly appreciated.
I don't know which version of Excel you work with.
Anyway you can try this :
Create a new sheet.
Go to Data in the ribbon to get external data and choose "From web".
Input the url of your page ie https://www.capfriendly.com/browse
After a moment you should retrieve "Results" data that you can load with or without structure modifications. You now have a data table in your new sheet.
You can now access it with Vlookup or similar function, with VBA code or with formulas, to put specific data on specific cells of specific sheets like you need to.
Hope it helps.
I have a bunch of data in Tableau. I'd like to get it into Excel.
Instead of making a report, then parsing that report, I'd like to hook Excel up directly to Tableau.
Tableau is grabbing data from a database, but due to "logic" we can't hook Excel up directly to the database... as easy as Excel makes it to do...
Is there a way to make an ODBC connection or some other power query connection directly from Excel to Tableau?
You can export a view to a CSV by adding .csv to the URL. You can pass parameter values using query strings, but not filter values unfortunately.
http://[Tableau Server Location]/views/[Workbook Name]/[View Name].csv?[Parameter Name]=[Value]&[Parameter Name]=[Value]
A few things to note:
Remove the spaces in your workbook name, view name, and parameter names. Special characters should also be removed, not url encoded.
URL encode your parameter values
You will get ALL of the fields from your view. This means your row, column, "detail", text label, and I believe caption values as well. If the same field is in your rows as well as text labels, it will show up twice on your exported CSV.
Make sure to test your URL thoroughly before you use it, including changing your parameter values to make sure they are working too.
The easiest way to do that is to export the different sets individually. See example below:
We're trying to provide users the ability to download a prepared Excel report from a SharePoint site. The template for the report, containing a PivotTable, will be present in a shared library. Users don't directly interact with Excel, but with webpages instead. Based on the user's filter selections on these webpages, an option to download a "prepared" report will be available.
The objective here is to pass the selected filter parameters to the Excel Services via REST on a URL call, and obtain the prepared workbook as a downloadable.
So far, we've been able to download the workbook as-is:
http://server/_vti_bin/ExcelRest.aspx/sites/test/Shared%20Documents/PivotPOC.xlsx/Model?$format=workbook -- this works.
The pivot filter value column is situated in Column B, so to pass filter values, we tried this:
http://server/_vti_bin/ExcelRest.aspx/sites/test/Shared%20Documents/PivotPOC.xlsx/Model?Ranges('B1')=David&$format=workbook -- this doesn't work -- and shows up this error on Firefox in the console:
The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.
What is the right way to pass parameters to a PivotTable when using Excel Services?
How to pass simple strings and integers?
How to pass values for multi-valued parameters? Comma separated?
How to pass MDX members?
Also, is there a query string length limit?
I would love to know how to import a single value from my Access database into an Excel cell.
Alternatively removing the header would be a good start.
The query
SELECT SUM(DEMANDS) AS TOTAL FROM [DB PROD]
gives me a header named TOTAL and, right below it, the sum I'm interested in. I use this query from within Excel (Data > Get External Data > From Access). How can I only get the sum in a single Excel cell?
One way to accomplish your goal would be to put your existing query on a different Sheet, say Sheet2, so the column header appears in Sheet2!A1 and the value appears in Sheet2!A2. Then reference the value cell from elsewhere in the Excel document. (The formula will look something like =Table_test.accdb[TOTAL].)
If you had several queries you could presumably keep them together (side by side) on the same sheet. You could also hide the query sheet so the "magic" would be more transparent to the user.
I am not sure I understand what you are doing, but, in order to read Access data from Excel, you need to do the following:
programmaticaly open a connexion in your Excel code, pointing to your
access database (let's say an ADO connexion for example)
then execute your 'SELECT' through this connection, using the ADODB.command object. That will return the requested value
another option would be to open a local recordset in Excel,based on your SQL intruction, and read the value.
Then do not forget to close your connexion