Web.contents power query reference cell

2.4k views Asked by At

Please have a look at the following code

Source = *Web.Page(Web.Contents(""https://in.finance.yahoo.com/quote/20MICRONS.NS/history?p=20MICRONS.NS"")*)

For the italics text i.e. the hyperlink, I am trying to link it to a cell. Can anyone tell me how this can be done?

I tried using the Cells tag but in vain

1

There are 1 answers

7
Marc Pincince On

I'm not certain what you are asking, but if you are saying that you want to replace "https://in.finance.yahoo.com/quote/20MICRONS.NS/history?p=20MICRONS.NS" with a URL from a column, and bring in that URL's info, you might try Web.Page(Web.Contents([Custom])), where [Custom] is the column with the URLs you want to use. This will embed a table of information for each URL listed in the "Custom" column, in that URL's corresponding row.

For instance, if the column "Custom" has https://in.finance.yahoo.com/quote/20MICRONS.NS/history?p=20MICRONS.NS in it, like this:

enter image description here

...then creating a new column with Web.Page(Web.Contents([Custom])) would embed this table:

enter image description here

...in the new column, like this:

enter image description here

Expanding the new column (in this case, "Custom1") would give you something like this:

enter image description here

And expanding the "Data" column would give you something like this:

enter image description here

I believe the info in "Column1.1" and "Column2" is what you are after from the URL you provided.

enter image description here


An edit following our comment discussion is below

Using Excel 2016, I set up a worksheet with the URL in column B, like you said yours is. Like this:

enter image description here

Then I click in either cell A1 or B1, and then I click the "Data" tab and the button to create a query from a table:

enter image description here

...which gives me this:

enter image description here

...and I click "OK", which gives me this in the Power Query Editor:

enter image description here

Then I click the "Add Column" tab and "Custom Column" button...

enter image description here

...and fill out the pop-up screen like this:

enter image description here

...and click "OK"...which gives me this:

enter image description here

Then I click the button at the top right of the "Custom" column...enter image description here...to expand the tables in the "Custom" column and get this:

enter image description here

Then I click the button at the top right of the "Data" column...enter image description here...to expand the tables in the "Data" column and get this:

enter image description here

Here's my query code:

let
Source = Excel.CurrentWorkbook(){[Name="Table5"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Custom", each Web.Page(Web.Contents([Column2]))),
#"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Caption", "Source", "ClassName", "Id", "Data"}, {"Caption", "Source", "ClassName", "Id", "Data"}),
#"Expanded Data" = Table.ExpandTableColumn(#"Expanded Custom", "Data", {"Column1", "Column2"}, {"Column1.1", "Column2.1"})
in
#"Expanded Data"