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 mphillenga ,
Just checking in to see if you query is resolved and if any responses were helpful. If so, kindly consider marking the helpful reply as 'Accepted Solution' to help others with similar queries.
Otherwise, feel free to reach out for further assistance.
Thank you.