Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Dynamic URL in Powerquery

Hi,

I'm making use of this static connection to an API, this works fine:

 

= Csv.Document(Web.Contents("https://api.xxxxxx.com/xxxxxxxxxxx/reports/export?format=csv&X-API-KEY=xxxxxxxxxxxxx&start_date=2017-01-01&end_date=2019-03-31&filter_id=5cb86085e3252"),[Delimiter=",", Columns=100, Encoding=1252, QuoteStyle=QuoteStyle.None])

 

What I now want to do is make the end date dynamically. it should always pull the data until the last day of the previous month. This is the query that I ended up with:

 

= Csv.Document(Web.Contents("https://api.xxxxxx.com/xxxxxxxxxxx/reports/export?format=csv&X-API-KEY=xxxxxxxxxxxxx&start_date=2017-01-01&end_date="&Date.ToText(Date.AddDays(Date.StartOfMonth(DateTime.Date(DateTime.LocalNow())),-1),"yyyy-MM-dd")&"&filter_id=5cb86085e3252"),[Delimiter=",", Columns=100, Encoding=1252, QuoteStyle=QuoteStyle.None])

 

The first query works fine every time. When using the second query i keep getting the error "Expression.Error: Access to the resource is forbidden."

 

What am i doing wrong?

1 ACCEPTED SOLUTION
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous ,

I could not modify the URL to achieve your result, maybe you could add an custom column to filter your data:

if [Date]<=DateTime.Date(DateTime.LocalNow())
then 1 else 0

1.PNG2.PNG

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous ,

I could not modify the URL to achieve your result, maybe you could add an custom column to filter your data:

if [Date]<=DateTime.Date(DateTime.LocalNow())
then 1 else 0

1.PNG2.PNG

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks @v-danhe-msft , that's a great solution. I tried it out and it works, but I often to continue to have these error messages that make it impossible to pull the data. After trying it with some other data sources it seems it really has to do with the API, it's just not stable enough, so nothing to do about that unfortunately!


Thank you for your help on this!
Bas

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.