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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Marie-Eve
New Member

Need help with relative path and query

Hello,

I need help building my source in Power Query to link to this site https://mpr.datamart.ams.usda.gov/services/v1.1/reports/2498?q=report_date=6/19/2024&allSections=tru... and be able to have it update automatically once online.  Like many others, I have started with this blog to build my query  https://blog.crossjoin.co.uk/2016/08/16/using-the-relativepath-and-query-options-with-web-contents-i...

 but I get this error message (basically the name "report_date" is not recognized)

MarieEve_0-1718890766994.png

 

It's like the query doesn't accept the double = with this part: q=report date= 

When I take it out, of course the url doesn't work, but if I copy it on a web page and add report_date= manually it does reach the page.  So it's basically just the syntax that is problematic.  

 

I found this document that explain the logic of the site URL https://mpr.datamart.ams.usda.gov/LMPRS-API-User-Guide.pdf but I can't get passed that glitch.  I've tried for a few days now to write the query or to find if anybody had this problem but couldn't find anything.  Hopefully someone here can help 🙂

3 REPLIES 3
Marie-Eve
New Member

Thanks a lot!  I should have asked sooner 😄

 

WanderingBI
Resolver III
Resolver III

I think it is working with below code, you can use it either with the full url or with the relative part and the query.

Maybe the reason why you had trouble is that the API blocks you out when you do too many requests. After waiting a few minutes it will work again.

 

let
    // Source = Json.Document(Web.Contents("https://mpr.datamart.ams.usda.gov/services/v1.1/reports/2466/Summary?q=report_date=08/05/2019"), 65001),
    pathBase = "https://mpr.datamart.ams.usda.gov/services/v1.1/",
    pathRelative = "reports/2466/Summary?",
    pathQuery = "q=report_date=08/05/2019",
    pathFull = pathBase & pathRelative & pathQuery,
    Source = Json.Document(Web.Contents(pathFull), 65001),
    
    yesterdayDate = DateTime.ToText(Date.AddDays(DateTime.LocalNow(), -1), "yyyy-MM-dd"),
    queryWithTodayDate = "report_date=" & yesterdayDate,
    SourceRelative = Json.Document(
        Web.Contents(pathBase, [
            RelativePath = pathRelative,
            Query = [q = queryWithTodayDate]
        ])
    )
in
    Source

 

Hello, I was able to recreate this with the the url in my original request and tried to replicate this with prior 2 days but it's not working. 

I duplicated the request and change this part to -2 but it still showed me the data of -1

yesterdayDate = DateTime.ToText(Date.AddDays(DateTime.LocalNow(), -1), "yyyy-MM-dd"),

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.