Forum Discussion

_Parjam_'s avatar
_Parjam_
Copper Contributor
Jan 22, 2021

STOCKHISTORY FUNCTION

Is there any way to create a stable query with the data spill from the STOCKHISTORY function. I spilled the data to a spreadsheet and created a dynamic named range which captures the data spill, I added it to a query, with the create blank query option and the Excel.currentworkbook() command, this works if the dynamic range is populated, but when the dynamic range is not populated it messes up the query. Is there a work around or a stable solution to this matter?  

10 Replies

  • SergeiBaklan's avatar
    SergeiBaklan
    Diamond Contributor

    _Parjam_ 

    What do you mean under "not populated", STOCKHISTORY() returns CALC error or N/A for some records? If the latest in Power Query you may remove rows with errors or replace errors on something.

    • _Parjam_'s avatar
      _Parjam_
      Copper Contributor

      SergeiBaklan STOCKHISTORY loads the data to the sheet, from there I use an Offset formula in a named range to select the data, then I create a query where I merge the named range with a table. The problem occurs in the query, when for example I change the dates or the ticker in the STOCKHISTORY formula, as the fresh data is loaded for a moment there is no data on the sheet, and it seems like the query looses the named range connection, and it does not update the query with the new data loaded. I suspect that the problem is that for an instant the named range goes from 4 columns to 1 cell to then go back to 4 columns. Can you suggest a better way to include a data spill which is not possible to structure as a table in a power query or am I doing something wrong? 

      • SergeiBaklan's avatar
        SergeiBaklan
        Diamond Contributor

        _Parjam_ 

        Let me clarify the situation:

        - let say STOCHHISTORY() returns data in D4

        - you add named range as =Sheet1!$D$4# and Power Query it as = Excel.CurrentWorkbook(){[Name="MyName"]}[Content]

         

        Here is the question did you use first row as header, or use Column1, Column2, etc? Changing the spill do you change the structure of the columns (their names, number, etc) and if yes how do you handle that in query?

         

        Next, "it does not update the query with the new data loaded" - which error do you see in Power Query in this case?

         

        In general it's much better to have small sample file to check.

Resources