Forum Discussion
Connect to file with dynamic link embbed in a webpage
Hello everyone,
I have a complex challenge to solve.
I need to extract a list of companies, available in a file linked in public agency webpage.
Instead of manually downloading the file from the website and importing to Power BI, I was looking for a way to automatically retrieve it from the webpage using power query.
This was possible by right clicking the file link in the webpage, copying the address and connecting to it using the power query web connector.
The problem is that, when this agency updates the file once a year, the file address changes. They add the update date to the link, example https://www.agency_webpage.pt/list-of-companies_22_02_2024.pdf. They also don't update it on the same day and month each year, so next year the link could be https://www.agency_webpage.pt/list-of-companies_18_01_2025.pdf, making it impossible to dynamically change the date on the file address using the web connector parameter [RelativePath], like:
Source = Pdf.Tables(Web.Contents("https://www.agency_webpage.pt/list-of-companies_22_02_",
[RelativePath = Number.ToText(Date.Year(DateTime.Date(DateTime.LocalNow())))]),
[Implementation="1.3"])
I created a query to scrap the file link from the webpage html code (fetching it from a href line code) using the Web.BrowserContents connector, that returns a string with the file link, #"Fetch File Address Query". Then I created a second query to extract the file, using the Web.Contents connector, with the agency website address as the first parameter and referenced the #"Fetch File Address Query" query in the parameter [RelativePath], like so:
Source = Pdf.Tables(Web.Contents("https://www.agency_webpage.pt/",[RelativePath = #"Fetch File Address Query"]), [Implementation="1.3"]),
This solution returned the error: "Formula.Firewall: Query references other queries, so it may not directly access a data source.".
I've tried changing the #"Fetch File Address Query" to a function and this way it worked on the Desktop. I'm able to apply and manually refresh the report in Power BI desktop. But after publishing to Power BI Service, it's impossible to manually refresh or schedule refresh in the service because it returns an error "Scheduled refresh is disabled because at least one data source is missing credentials." and the option to manage the credentials is greyed out:
After extensive research, I didn't find any other way to create a query that could connect to a file with a dynamic address, located in a webpage, that worked properly in power bi service.
Has anyone had a similar situation and was able to find a solution?
8 Replies
- lbendlin
Super User
That's a very common error pattern. your RelativePath must include the
list-of-companies_22_02_bit, or whatever the new name is. If you want to supply the Relative Path dynamically then that must happen inside the same query partition.
- Luis_RBDOFrequent Visitor
I've created a function to fetch from the website and return as a string the bit that changes every year . When I call the function on the Relative Path, it works on Power BI Desktop but not on the service. The "Data source credentials" section greys out, making it impossible to configure.
- lbendlin
Super User
You are trying to automate something that changes once a year?