Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

Dynamically sending data to call api from the power bi report

I am trying to build a report where I am getting data from an API. This API needs a body for the todate and fromdate. I am able to pass today's date and last 30 days. 
I want to input this "30" from the user selection. I want a tile slicer filter with 7,15,30,60.. values and when 7 is selected, it should fetch last 7 days data and respectively for all others. 
This is the code I am using to call the API with a parameter made in Power query called as DayNo. 


let
today = DateTime.LocalNow(),
// Construct the URL with query parameters
url = "<<url>>",
queryString = "?fromdate=" & DateTime.ToText(today - #duration(DaysNo,0,0,0),"yyyy-MM-dd") & "&todate=" & DateTime.ToText(today,"yyyy-MM-dd"),
fullUrl = url & queryString,

// Retrieve data from the web source
source = Json.Document(Web.Contents(fullUrl)),
in 

source

1 Reply

  • Dynamic M Query parameters only work with Direct Query data sources.  Your API data source is not Direct Query.