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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Rest API Dynamic Date Query


Hi Everyone.

I am having a problem with the Ariba API dynamic time filter. Code is listed below.

 

Source = Json.Document(Web.Contents("https://openapi.ariba.com/api/analytics-reporting-details/v1/prod/views/templatename?realm=myrealm&filters={""createdDateFrom"":""2020-02-01T00:00:00Z"",""createdDateTo"":""2020-02-06T00:00:00Z""}")),

 

 

Basically I want to make date dynamic ( from and to ) . I want to detect 2 months time period dynamically selected.

 

{""createdDateFrom"":""2020-01-01T00:00:00Z"",""createdDateTo"":""2020-02-29T00:00:00Z""}

 

Many Thanks in advance.

 

1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

You can adjust your code to:

let
    startMonthDate = Date.StartOfMonth( Date.From( DateTime.LocalNow() ) ) ,
    endDate = Date.AddDays(  startMonthDate , -1 ),
    startDate = Date.AddMonths( startMonthDate , -2 ),
    endDateText = Date.ToText( endDate, "yyyy-MM-ddT00:00:00Z" ),
    startDateText = Date.ToText( startDate, "yyyy-MM-ddT00:00:00Z" ),
    Custom1 = "https://openapi.ariba.com/api/analytics-reporting-details/v1/prod/views/templatename?realm=myrealm&filters={""createdDateFrom"":"& startDateText &",""createdDateTo"":"&endDateText&"}"
in
    Custom1

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

View solution in original post

6 REPLIES 6
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

Try something like this.

Edited 2.0:

 

 

let
    endDate = Date.From( DateTime.LocalNow() ),
    startDate = Date.AddMonths( endDate , -2 ),
    endDateText = Date.ToText( endDate, "yyyy-MM-ddT00:00:00Z" ),
    startDateText = Date.ToText( startDate, "yyyy-MM-ddT00:00:00Z" ),
    Custom1 = "https://openapi.ariba.com/api/analytics-reporting-details/v1/prod/views/templatename?realm=myrealm&filters={""createdDateFrom"":"& startDateText &",""createdDateTo"":"&endDateText&"}"
in
    Custom1

 

 

 

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

You can adjust your code to:

let
    startMonthDate = Date.StartOfMonth( Date.From( DateTime.LocalNow() ) ) ,
    endDate = Date.AddDays(  startMonthDate , -1 ),
    startDate = Date.AddMonths( startMonthDate , -2 ),
    endDateText = Date.ToText( endDate, "yyyy-MM-ddT00:00:00Z" ),
    startDateText = Date.ToText( startDate, "yyyy-MM-ddT00:00:00Z" ),
    Custom1 = "https://openapi.ariba.com/api/analytics-reporting-details/v1/prod/views/templatename?realm=myrealm&filters={""createdDateFrom"":"& startDateText &",""createdDateTo"":"&endDateText&"}"
in
    Custom1

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Anonymous
Not applicable

Hi @Mariusz .

 

Thank you. Really appreciated. The Code is working for me.

Just a last Question. What if i want to skip the current month and filter for last two months. 

For Example: i want to skip the current march month 3 days etc, and filter the last whole february and january Months.

 

Many Thanks.

 

Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 


Are you looking for the current month and previous or last two months?

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Hi Mariusz - Please help. I have a similar requirement and struggling as I dont understand programming that well. I am trying to simply get the end date to dynamically pick the previous day or yesterdays date (i.e today -1). Below is my code that is picking a particular date range at the moment I need help with the end date to change dynamically. 

 

url = "https://abc.abcedfoperations.com/abcccc-adminisabc/c3/GetDataBCDEFG",
body = "{""filters"":{""fromDate"":""2020-01-01"",""endDate"":""2021-03-25""}}",
Parsed_JSON = Json.Document(body),
BuildQueryString = Uri.BuildQueryString(Parsed_JSON),
Source = Json.Document(Web.Contents(url,[Headers = [#"Content-Type"="application/json",#"Authorization" = "Bearer "&APILoopBackToken(),#"Ocp-Apim-Subscription-Key" = "abcdefxxxxxxxabcdefxxxxxabc"],
Content = Text.ToBinary(body) ] )),
Response = Source[Response],
#"Converted to Table" = Table.FromList(Response, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"Entity",.........

Anonymous
Not applicable

Hi @Mariusz .

Thanks for reaching out.

I am looking for Current Month and last month.  Like today its 3 march 2020, so i want it automatically select from 3/01/2020 to 3/03/2020. The format must be json "YYYY,MM,DDTime" .

Thank you.

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.

March Power BI Update Carousel

Power BI Community Update - March 2026

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