Web Data Query: Automatically Add or Append New Web Query Data to Previous Data

krismiller1982

New Member
Joined
May 23, 2022
Messages
8
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I'm still struggling to find a solution after several months of searching for an answer. Surely this concept is simple. Yes?

I have setup a web query to grab information from Yahoo Finance ( STOCKHISTORY function does not include adjusted stock prices, so I must use Yahoo Finance ). I'm trying to accomplish the following:

Upon web query refresh, new data is added or appended to the previously queried data. Thus automatically adding new rows of daily data into the table. Is there a way to do this? I appreciate anyones help. Thank you.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
try this setting under Table design
1663921970218.png
 
Upvote 0
Need more information. ie. Web site you are querying. Full URL. You don't indicate how you are running your web query, VBA? Power Query? Some other method. Help us help you. More detailed information.
 
Upvote 0
Need more information. ie. Web site you are querying. Full URL. You don't indicate how you are running your web query, VBA? Power Query? Some other method. Help us help you. More detailed information.
My apologies for lack of info. I'm using "Get Data from Web". I use the Power Query editor to transform certain elements of the table. But I'm open to using VBA if its more elegant. The webpage I use for the query is SPDR S&P 500 ETF Trust (SPY) Stock Historical Prices & Data - Yahoo Finance. When Excel grabs data from that URL, it populates the most recent 100 market days. I'm trying to find a way for new daily data to automatically append to the older data upon refreshing while not losing the older data..... I'm adding a quick screen shot to show how the data looks if that helps. I appreciate your time & help.
 

Attachments

  • Screen Shot 2022-09-23 at 6.24.53 PM.png
    Screen Shot 2022-09-23 at 6.24.53 PM.png
    159.5 KB · Views: 17
Upvote 0
You could do this with a VBA class which handles the AfterRefresh event on the web query. When the refresh occurs it copies new rows from the web query table to another table which contains all the historic data rows.
 
Upvote 0
You could do this with a VBA class which handles the AfterRefresh event on the web query. When the refresh occurs it copies new rows from the web query table to another table which contains all the historic data rows.
Thank you. I'll look into how I can do that. I know nothing about VBA, but will search.
 
Upvote 0
After searching I found a solution. However I would like to learn how to do this using VBA. I'll update the answer once I find it.

"In the interest of keeping the solution with the question in case those websites are no longer accessible, the basic premise of incremental updates in the Excel for Windows version of Power Query is as follows:
  1. Create your initial PQ with the transforms that you want and output to an Excel Table.
  2. Create a second PQ referencing the Excel Table you just created, and set it as “Connection Only”. This preserves the existing data.
  3. Return to edit the PQ you created in Step 1 by adding a step to append the output of the second PQ. This runs the first query to get more recent data, then appends the existing data that you preserved in Step 2 onto that result for the finished output.
  4. Add steps to the first query after that to de-dupe and sort the results, if necessary. This will obviously require some kind of unique identifier on each record (a unique date/time, an ‘id’ field, whatever provides some unique value). You can always remove that unique id column after de-duping as a last step if you don’t want to see it in the final output."
 
Upvote 0
Solution
  1. Create your initial PQ with the transforms that you want and output to an Excel Table.
  2. Create a second PQ referencing the Excel Table you just created, and set it as “Connection Only”. This preserves the existing data.
  3. Return to edit the PQ you created in Step 1 by adding a step to append the output of the second PQ. This runs the first query to get more recent data, then appends the existing data that you preserved in Step 2 onto that result for the finished output.
  4. Add steps to the first query after that to de-dupe and sort the results, if necessary. This will obviously require some kind of unique identifier on each record (a unique date/time, an ‘id’ field, whatever provides some unique value). You can always remove that unique id column after de-duping as a last step if you don’t want to see it in the final output."

A very good solution and certainly far simpler than using VBA!

In Step 2 for the second PQ, the Date column contains dates and times as 00:00:00. Change the Data Type from 'Date/Time' to 'Date' so that the dates are in the same format as the first PQ, thereby allowing duplicates to be removed in Step 4.
 
Upvote 0
eb". I use the Power Query editor to transform certain elements of the table. But I'm open to using VBA if its more elegant. The webpage I use for the query is SPDR S&P 500 ETF Trust (SPY) Stock Historical Prices & Data - Yahoo Finance. When Excel grabs data from that URL, it populates the most recent 100 market
I'm still struggling to find a solution after several months of searching for an answer. Surely this concept is simple. Yes?

I have setup a web query to grab information from Yahoo Finance ( STOCKHISTORY function does not include adjusted stock prices, so I must use Yahoo Finance ). I'm trying to accomplish the following:

Upon web query refresh, new data is added or appended to the previously queried data. Thus automatically adding new rows of daily data into the table. Is there a way to do this? I appreciate anyones help. Thank you.
Hi krismiller1982,
Did you find a solution using VBA? Please upload an excel-sheet if you did. Thx!
 
Upvote 0

Forum statistics

Threads
1,215,720
Messages
6,126,439
Members
449,314
Latest member
MrSabo83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top