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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
chengzong
Regular Visitor

Can not add "$filter" operation in URL with variable when use OData Feed.

Hi Team,

I am use OData Feed to fetch Data from the API.

 

let
    apiURL = "https://api.xxxx.com/Users?$filter=ModifiedDate gt 2024-11-18T12:00:00Z",
    apiHeaders = [
        #"Authorization" = access_token
    ],
    Source = OData.Feed(apiURL, null, [Headers=apiHeaders])
in
    Source

 

 This piece of code works. But when I put the date into a variable. 

 

let
    apiURL = "https://api.xxxx.com/Users?$filter=ModifiedDate gt " &   formattedStartDate ,
    apiHeaders = [
        #"Authorization" = access_token
    ],
    Source = OData.Feed(apiURL, null, [Headers=apiHeaders])
in
    Source

 

I got a waring "Some data sources may not be listed because of hand-authored queries" in Data Source settings.
Screenshot 2024-11-20 104249.png

 

And this can be refreshed in local PowerBI Desktop. But after I published to the Cloud. Failed to refreshe the data.
Screenshot 2024-11-20 104828.png
 

1 ACCEPTED SOLUTION
chengzong
Regular Visitor

Hi @danextian .
Thanks for your replay, but this issue still exist.

One interesting thing is that when I use a constant string or set the formattedStartDate as a string parameter. It works. 
But when I use the code to generate this variable, or set the type of the parameter to Date/Time. This issue still exist.

 

 

currentDateTime = DateTime.LocalNow(),    
formattedStartDate = DateTime.ToText(currentDateTime, "yyyy-MM-ddThh:mm:ssZ"),

 

 

 

By the way, I find a workaround, I do not know the reseaon, but it works for me.

 

 

    Source = OData.Feed(
        "https://api.xxxx.com/Users?$filter=ModifiedDate gt @testdate", 
        null, 
        [
            Query=[#"@testdate" = formattedStartDate], 
            Headers=apiHeaders])

 

 

REF: https://blog.crossjoin.co.uk/2023/01/15/using-odata-feed-and-the-query-option-to-avoid-the-dynamic-d...

View solution in original post

3 REPLIES 3
chengzong
Regular Visitor

Hi @danextian .
Thanks for your replay, but this issue still exist.

One interesting thing is that when I use a constant string or set the formattedStartDate as a string parameter. It works. 
But when I use the code to generate this variable, or set the type of the parameter to Date/Time. This issue still exist.

 

 

currentDateTime = DateTime.LocalNow(),    
formattedStartDate = DateTime.ToText(currentDateTime, "yyyy-MM-ddThh:mm:ssZ"),

 

 

 

By the way, I find a workaround, I do not know the reseaon, but it works for me.

 

 

    Source = OData.Feed(
        "https://api.xxxx.com/Users?$filter=ModifiedDate gt @testdate", 
        null, 
        [
            Query=[#"@testdate" = formattedStartDate], 
            Headers=apiHeaders])

 

 

REF: https://blog.crossjoin.co.uk/2023/01/15/using-odata-feed-and-the-query-option-to-avoid-the-dynamic-d...

Anonymous
Not applicable

Hi @chengzong 

It is glad that you solve  your problem ,you can consider to accept your answer as solution so that more user can refer to.

 

Best Regards!

Yolo Zhu

 

danextian
Super User
Super User

Hi @chengzong 

 

That is expected as what you did created a dyanmic data source - https://learn.microsoft.com/en-us/power-bi/connect-data/refresh-data#refresh-and-dynamic-data-source... . Use relative path

let
    baseURL = "https://api.xxxx.com/",
    relativePath = "Users?$filter=ModifiedDate gt " &   formattedStartDate",
    fullURL = baseURL & relativePath,
    apiHeaders = [
        #"Authorization" = access_token
    ],
    Source = OData.Feed(fullURL, null, [Headers = apiHeaders])
in
    Source

 

danextian_0-1732078204632.png

danextian_1-1732078215073.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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