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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
manirohit
New Member

Define a variable in M query and concatenate to form url

Hi All,

 

Need help in defining a date time varibale in M query. I have an API which uses from date and to date as query parameter. I want to pass current date time in the to date and yesterday date time in from date.

 

I somehow defined the datetime like below

fromdate = Date.AddDays(Date.From(DateTime.FixedLocalNow()),-1),
todate = DateTime.FixedLocalNow(),

but i need to pass these values in the URL call, How can I use above parameters to form the API URL?  

auth_url = "https://abc.com/alldata?fromDate=&toDate=",

Let me know if there is another way of doing it or if possible pick the from date and to date values from some other table.

 

 

Thanks in advance.

1 ACCEPTED SOLUTION

Thanks @petrovnikitamai

 

I was able to achieve this from below. so basically the concatenation works with '&' and also the type should be text

 

fromdate = Date.AddDays(DateTime.From(DateTime.FixedLocalNow()),-1),
    todate = DateTime.FixedLocalNow(),
    fromDate = DateTime.ToText(fromdate),
    toDate = DateTime.ToText(todate),
    auth_url = "https://abc.com/alldata?fromDate="&fromDate&"&toDate="&toDate,

 

View solution in original post

2 REPLIES 2
petrovnikitamai
Resolver V
Resolver V

i guess

auth_url = "https://abc.com/alldata?fromDate='"&fromdate&"'toDate="

 

i'm no sure but try to use this code where "timezone", "start_dtime", "end_dtime" is text parametr

= Odbc.Query(source, "select shift_id,
start_dtime+'"&timezone&"' as start_dtime,
end_dtime+'"&timezone&"' as end_dtime
from shifts_segment
where start_dtime>='"&start_date&"' and end_dtime<='"&end_date&"'")

for example, start_dtime format is text 2017-08-01 00:00:00 

Thanks @petrovnikitamai

 

I was able to achieve this from below. so basically the concatenation works with '&' and also the type should be text

 

fromdate = Date.AddDays(DateTime.From(DateTime.FixedLocalNow()),-1),
    todate = DateTime.FixedLocalNow(),
    fromDate = DateTime.ToText(fromdate),
    toDate = DateTime.ToText(todate),
    auth_url = "https://abc.com/alldata?fromDate="&fromDate&"&toDate="&toDate,

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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