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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
arekay
Regular Visitor

Refresh failing in PBI Service - Date.ToText syntax causing error?

Hi all,

 

I'm fairly new to Power Query, and am having trouble with a query that refreshes fine in PBI desktop, but fails when I upload it to our workspace.

 

The query makes a call to a REST API that takes a start and end date as parameters. The start date is static, but the end date needs to be dynamic to always take whatever today's date is when the code runs.

 

Here is the relevant section of my code.

 

 

let
    Source = (Page as number) =>

let
    Source = Json.Document(Web.Contents(
        "[MY API ENDPOINT]",
        [
            Query=
            [
                startdate = "2021-09-01",
                enddate = Date.ToText(Date.From(DateTime.LocalNow()),[Format = "yyyy-MM-dd"]),
                page_index = Number.ToText(Page)
            ],
            Headers = header, //define elsewhere, contains authentication keys for the API
            Content = Text.ToBinary("")
        ]
    ))

 

This works fine locally, but when I upload it to our workspace, I get an error. However, if instead of defining "enddate" dynamically, I just pass a static text string the same way I do for "startdate", everything works.

I know the "How to get your questions answered" post says don't post screenshots of error messages, but this one seems relevant so apologies in advance! This is what I get when I use the dynamic date

Capture.PNG

 

 

 

 

 

Obviously I'm not an expert, but the second and the last lines here look like they're saying that the problem is the format option in Date.ToText function. I can't test that because if I don't include that option in the code, the default result is dd/MM/yyyy, which the API I am connecting to won't recognise (it only accepts yyyy-MM-dd)

 

Is there another way to generate a dynamic date, with the format the API I'm accessing requires, without triggering this error?

 

Thanks in advance!

Ryan

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @arekay ,

Try changing your format argument like this:

 

enddate = Date.ToText(Date.From(DateTime.LocalNow()), "yyyy-MM-dd"),

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

2 REPLIES 2
BA_Pete
Super User
Super User

Hi @arekay ,

Try changing your format argument like this:

 

enddate = Date.ToText(Date.From(DateTime.LocalNow()), "yyyy-MM-dd"),

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Thanks @BA_Pete ! That seems to have sorted it

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.