January 23, 2021
I am looking at building a Stock Portfolio using Excel
The problem is that Excel doesn't have the function ImportHTML and everything that I have tried is not working. I want to avoid using Power BI so wondering if anyone has any ideas on how I can achieve my goal using Power Query or a custom function.
Keep in mind that I don't want to download any more data than is needed and Google Sheets ImportHTML meets that requirement.
Thanks,
Kevin
VIP
Trusted Members
December 7, 2016
Hello,
I am no Google Sheets user so I don’t know how ImportHTML function works, but when reading about it I think it is similar to get data from web using Power Query. Have you tried it?
Br,
Anders
January 23, 2021
Hi Anders, thanks for the reply. Unfortunately, my Youtube video was removed from my post, but what I can tell you is that ImportHTML allows me to specify the table to pull data. I then use the Index function to get the specific data I want. This is extremely useful when pulling data from sites such as Finviz where the summary page contains many tables. I have not figure out a way to do this with "get data from web" as it seems to want a web page that contains a single table. For example, one of the common ways I use this is as follows:
=Index(ImportHMTL("http://finviz.com/quote.ashx?t="&B2,"table", 8), 11, 6)
This call will get the data for a specific ticker symbol from table number 8 and then the index function will return the Earnings data from row 11 col 6.
=Index(ImportHMTL("http://finviz.com/quote.ashx?t="&B2,"table", 8), 1, 4) - returns the PE ratio
If there is a way to do this using the method you described, can you possibly provide an example?
Thanks,
Kevin
July 16, 2010
Hi Kevin,
When you provide Power Query with a URL to get data from, it will present you a list of the tables on that page from which you can choose the one you want. Without an example link from you I can't give you an example in return, but you can try it yourself by following the link to the tutorial Anders provided you above.
Mynda
January 23, 2021
Hi Mynda,
The example links are in my previous post. The &B2 portion is just a parameter which is a stock ticker such as AAPL. I will play around with Power Query, but I'm not very proficient in it.
On another note, I did discover the Stock feature under the Data tab which works fairly well, but it does not return all of the attributes I need.
Cheers!
Kevin
VIP
Trusted Members
December 7, 2016
Hi Kevin,
A bit off topic perhaps, but seeing you want financial data, have you checked out what Excel Data Types or STOCKHISTORY function can do?
You need of course to have Excel 365 in order to use these.
You can read more about the stocs financial data type here.
And more about STOCKHISTORY function here.
Br,
Anders
January 23, 2021
Thanks Anders,
I did look at the stock history function, but unfortunately, it only returns the close, unlike Google Sheets ImportHTML() where I can't go after any specific attribute from a table. I also played around the Power Query suggested by both you and Mynda, but it is not really what I am looking for because I need to return specific attributes in the table of stocks. So given the following example:
A B C D E F G
1 Symbol Price Change % Change $ Gain % Gain $ Dividend
2 VXC $46.63 0.39% $0.90 12.26% $25.47 $0.17
3 AQN $21.98 0.55% $12.00 0.32% $7.05 $0.00
I currently acquire the values for row 2 in Google Sheets using either ImportHTML() (For Finviz or other sources) or GoogleFinance() as follows:
Price =GoogleFinance(A2, "Price")
Change % =GoogleFinance(A2, "Changepct")
Change $ =GoogleFinance(A2, "Change")
Dividend =Index(ImportHTML("http://finviz.com/quote.ashx?t="&A2,"table",8),7,2)
etc.
In Excel I can get most of the way to my goal using the "Stocks" Data Type in the Queries & Connections pane, which is actually perfect for my needs. Unfortunately, the Stocks data type is limited in the number of attributes it can return. It will not return attributes such as ATR, RSI, EPS, Dividend and many more. I can also use Power Query to download data from Finviz for a particular stock, but that is not dynamic which is needed because I am constantly adding new stocks to my portfolio. I even figured out how to parameterize the Power Query, but again I'm not sure how to achieve my requirement on the row by row basis from my portfolio since each row is a download of data from Finviz for a specific stock ticker. I suspect I will just have to live with what is available in the Stocks data type for now and hope Microsoft adds more attributes over time.
I have a great Stock Tracker built using Google Sheets, but I don't like the idea of Big Brother having access to my data. This is the only reason I am looking to rebuild using Excel.
Cheers!
July 16, 2010
Hi Kevin,
If you prefer, you can use STOCKHISTORY to get the close and you can calculate the change and change % by getting the close from the previous day also using STOCKHISTORY. Or you can just use the Stocks data type for these attributes (and the dividend), as you've already found.
You say "... I'm not sure how to achieve my requirement on the row by row basis from my portfolio since each row is a download of data from Finviz for a specific stock ticker. "
I don't know what you mean by this and it's difficult to help without an example of your desired end result and URL for the source data.
Mynda
January 23, 2021
Hi Mynda,
Sorry, I don't think I am doing a good job of explaining myself. Those fields I listed were just examples.... there are over a dozen attributes that I cannot get using Excel unless I use Power Query. Power Query just isn't a good solution for a dynamic list of stocks when I need real-time data for each row every time I open the workbook.
I'm sure an Excel guru like you could figure out a solution, but it is just beyond my capabilities given my current knowledge in Excel. I have decided to just stick with Google Sheets for this solution until Excel matures a bit more in this area. I would love to send you a Youtube link for a really nice Google Sheet Portfolio Manager, but the link was removed from my original post.
Cheers!
Kevin
1 Guest(s)