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

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
djanszentql
Helper I
Helper I

Dynamic Date Params in API Query String

I have 2 parameters/query strings in my API call that are sDate and eDate.  I need to set sDate dynamically to be TODAY()-90 to get the last 3 months of data.

 

My api call currently looks like this:

 

...&sDate="&Text.Replace(Date.AddDays(Date.From(DateTime.LocalNow()), -90),", ","-")&"edate=2020-12-21...

 

The error message I receive is: 

Expression.Error: We cannot convert the value #date(2020, 9, 23) to type Text.
Details:
Value=9/23/2020
Type=[Type]

 

I tried wrapping the Date.From in a Date.ToText function, but when I do that the API returns nothing.  Is there a test environment or way I can see what the variable looks like as I write my code in M?  It is very difficult to decipher when there is no debugging option.  Thanks!

1 ACCEPTED SOLUTION
djanszentql
Helper I
Helper I

Solution: 

 

Date.ToText(Date.AddDays(Date.From(DateTime.LocalNow()), -10),"yyyy-MM-dd")

View solution in original post

3 REPLIES 3
djanszentql
Helper I
Helper I

Solution: 

 

Date.ToText(Date.AddDays(Date.From(DateTime.LocalNow()), -10),"yyyy-MM-dd")

lbendlin
Super User
Super User

Do your conversion the other way round - use Text.From()

Here's a website that allows you to test API calls:  Online API Testing Tool | Test Your API Online (reqbin.com)

I just posted the solution.  Also, it wasn't the API call I was testing, but rather the M formula within the API call.  

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 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.