Forum Discussion
Cant understand why this is a dynamic data source?
- 6 months ago
GeraldGEmerick's response is spot on. Additionally, if you are trying to refresh in the service, last I checked Web.BrowserContents is not supported. You can get around this, though, with Web.Contents + Text.FromBinary.
To expand on Gerarld's response, you want to move the dynamic parts of your base url to RelativePath in the options param (details can be found here: https://learn.microsoft.com/en-us/powerquery-m/web-contents). To put it all together with a concrete example (that I think gets you what you want, but may need additional testing):
(Month as text) as table => let // Fixed (🤞) M Source = Web.Contents( "https://www.trade-tariff.service.gov.uk",[ RelativePath="/exchange_rates/view/" & Month, Headers=[], Query=[type="monthly"] ] ), ToHtml = Text.FromBinary( Source ), // Original M #"Extracted table from HTML" = Html.Table(ToHtml, {{"Column0", "TABLE.govuk-table.govuk-\!-margin-top-6 > * > TR > :nth-child(1)"}, {"Column1", "TABLE.govuk-table.govuk-\!-margin-top-6 > * > TR > :nth-child(2)"}, {"Column2", "TABLE.govuk-table.govuk-\!-margin-top-6 > * > TR > :nth-child(3)"}, {"Column3", "TABLE.govuk-table.govuk-\!-margin-top-6 > * > TR > :nth-child(4)"}, {"Column4", "TABLE.govuk-table.govuk-\!-margin-top-6 > * > TR > :nth-child(5)"}, {"Column5", "TABLE.govuk-table.govuk-\!-margin-top-6 > * > TR > :nth-child(6)"}}, [RowSelector = "TABLE.govuk-table.govuk-\!-margin-top-6 > * > TR"]), #"Promoted headers" = Table.PromoteHeaders(#"Extracted table from HTML", [PromoteAllScalars = true]), #"Changed column type" = Table.TransformColumnTypes(#"Promoted headers", {{"Currency units per £1", type number}, {"Start date", type date}, {"End date", type date}}), #"Filtered Rows2" = Table.SelectRows(#"Changed column type", each ([#"Country/territory"] = "Eurozone" or [#"Country/territory"] = "USA")), #"Choose columns" = Table.SelectColumns(#"Filtered Rows2", {"Currency code", "Currency units per £1", "Start date", "End date"}), #"Pivoted Column" = Table.Pivot(#"Choose columns", List.Distinct(#"Choose columns"[#"Currency code"]), "Currency code", "Currency units per £1", List.Sum) in #"Pivoted Column"
GeraldGEmerick's response is spot on. Additionally, if you are trying to refresh in the service, last I checked Web.BrowserContents is not supported. You can get around this, though, with Web.Contents + Text.FromBinary.
To expand on Gerarld's response, you want to move the dynamic parts of your base url to RelativePath in the options param (details can be found here: https://learn.microsoft.com/en-us/powerquery-m/web-contents). To put it all together with a concrete example (that I think gets you what you want, but may need additional testing):
(Month as text) as table =>
let
// Fixed (🤞) M
Source = Web.Contents(
"https://www.trade-tariff.service.gov.uk",[
RelativePath="/exchange_rates/view/" & Month,
Headers=[],
Query=[type="monthly"]
]
),
ToHtml = Text.FromBinary( Source ),
// Original M
#"Extracted table from HTML" = Html.Table(ToHtml, {{"Column0", "TABLE.govuk-table.govuk-\!-margin-top-6 > * > TR > :nth-child(1)"}, {"Column1", "TABLE.govuk-table.govuk-\!-margin-top-6 > * > TR > :nth-child(2)"}, {"Column2", "TABLE.govuk-table.govuk-\!-margin-top-6 > * > TR > :nth-child(3)"}, {"Column3", "TABLE.govuk-table.govuk-\!-margin-top-6 > * > TR > :nth-child(4)"}, {"Column4", "TABLE.govuk-table.govuk-\!-margin-top-6 > * > TR > :nth-child(5)"}, {"Column5", "TABLE.govuk-table.govuk-\!-margin-top-6 > * > TR > :nth-child(6)"}}, [RowSelector = "TABLE.govuk-table.govuk-\!-margin-top-6 > * > TR"]),
#"Promoted headers" = Table.PromoteHeaders(#"Extracted table from HTML", [PromoteAllScalars = true]),
#"Changed column type" = Table.TransformColumnTypes(#"Promoted headers", {{"Currency units per £1", type number}, {"Start date", type date}, {"End date", type date}}),
#"Filtered Rows2" = Table.SelectRows(#"Changed column type", each ([#"Country/territory"] = "Eurozone" or [#"Country/territory"] = "USA")),
#"Choose columns" = Table.SelectColumns(#"Filtered Rows2", {"Currency code", "Currency units per £1", "Start date", "End date"}),
#"Pivoted Column" = Table.Pivot(#"Choose columns", List.Distinct(#"Choose columns"[#"Currency code"]), "Currency code", "Currency units per £1", List.Sum)
in
#"Pivoted Column"
Excellent all working thanks so much for detailed explanation