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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
oseverma9
Frequent Visitor

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 1
Syndicate_Admin
Administrator
Administrator

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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