Forum Discussion
PowerBI data refresh due to dynamic data source. Help with adjusting the M script
- 1 year ago
Hi mphillenga ,
Thanks for reaching out in Microsoft Fabric Community.
The error "This dataset includes a dynamic data source..." occurs because the query still generates parts of the Web API request dynamically at runtime, particularly by using DateTime.LocalNow(). Power BI Service requires the URL to be fully evaluable at design time for scheduled refresh to work. Even though the dates are passed as parameters, the use of DateTime.LocalNow() results in dynamic URL generation at runtime, which causes the issue.To address this, you can restructure the query to use static parameters, like this:
Create two parameters:
StartDate (Type: Date, e.g., 2025-01-01)
EndDate (Type: Date, e.g., 2025-04-28)
Adjust the query like this:
let FixedStartDate = StartDate, FixedEndDate = EndDate, PeriodFromDate = Date.ToText(FixedStartDate, "dd-MM-yyyy"), PeriodToDate = Date.ToText(FixedEndDate, "dd-MM-yyyy"), QueryParams = [ onlyReportColumns = "no", periodFromDate = PeriodFromDate, periodToDate = PeriodToDate ], Source = Json.Document( Web.Contents( "https://organisation.software.com", [ RelativePath = "api/v1/reportDirectGet/projectHoursEmpWeek", Query = QueryParams ] ) ), Data = Source[jsondata], ConvertToTable = Table.FromList(Data, Record.FieldValues, Record.FieldNames(Data{0})), AutoTypeConversion = Table.TransformColumnTypes(ConvertToTable, List.Transform(Table.ColumnNames(ConvertToTable), each {_, type text}), "en-US" ) in AutoTypeConversionSome Helpful references:
Data refresh in Power BI - Power BI | Microsoft LearnChris Webb's BI Blog: Web.Contents(), M Functions And Dataset Refresh Errors In Power BI
Hope this helps. Please reach out for further assistance.
If this post helps, then please consider to Accept it as the solution to help the other members find it more quickly and a kudos would be appreciated.Thank you.
Hi v-veshwara-msft,
Thanks a lot.
To clarify, I'd like to get the latest data from the API everytime the PowerBI refreshes. Therefore I did not put a fixed EndDate in, but the "CurrentDate = Date.From(DateTime.LocalNow())" code.
Do you have idea how to ensure the PowerBI service request refreshes automatically, whilst grabbing the newest/ latest data every day?
Thanks,
Thanks for clarifying.
In Power BI Service, even though you want dynamic latest data, the query (including dates) must be static at refresh time. Using DateTime.LocalNow() makes the URL dynamic, which the Service cannot evaluate during scheduled refresh.
To solve this:
If your API supports it, skip passing periodToDate, so the API automatically returns up-to-today data.
Otherwise, use a parameter for EndDate and update it daily, either manually or using Power Automate.
Power BI needs the URL and its structure to be static, but the data can still change each day based on how your API handles missing or fixed parameters.
Hope this helps and let us know if you need any further assistance.
Please consider marking the helpful reply as Accepted Solution to assist others with similar issues.
Thanks,
Vinay.