Forum Discussion
Schedule refresh for Dynamic data source in Power BI
Hi Community,
Urgent help!
I have created the dashboard named "SCORE".
For accessing data, we are getting data from sharepoint folder and I add average calculation before combining all files in that folder
When I try to schedule refresh, I am getting the below error:-
This dataset includes a dynamic data source. Since dynamic data sources aren't refreshed in the Power BI service, this dataset won't be refreshed.
Data source for query1.
Also if we have code until navigation step. I can schedule the refresh. But, when I add m-code for calculating average, scheduling refresh throws dynamic source error. Even I'm not getting the data connnections option in under the semantic model.
M-code:
let
// Access SharePoint site and specify API version
Source = SharePoint.Contents("https://sharepoint.com/sites/AdvancedAnalyticsCenterofExcellence2/", [ApiVersion = 15]),
// Navigate through the folder structure to the target directory
#"SCORE Data Upload" = Source{[Name="SCORE Data Upload"]}[Content],
SCORE = #"SCORE Data Upload"{[Name="SCORE"]}[Content],
// Function to process each file
ProcessFile = (file as record) =>
let
// Load each table from file
TableFromXLSX = Excel.Workbook(Web.Contents(file[Folder Path] & file[Name]), null, true),
// Access the first worksheet in the workbook
FirstSheet = TableFromXLSX{[Item="SCORE", Kind="Sheet"]}[Data],
PromoteHeaders = Table.PromoteHeaders(FirstSheet, [PromoteAllScalars=true]),
// Remove certain columns (example columns "ColumnToRemove1", "ColumnToRemove2")
ColumnsToKeep = {"Region", "Country", "S", "C", "O", "R", "E", "SCORE Original","SCORE Adjusted","Difference - Original to Adjusted","Tier"},
FilteredColumns = Table.SelectColumns(PromoteHeaders, ColumnsToKeep),
// Filter certain values in the Region column (example to keep only non-null and non-zero)
FilteredRows = Table.SelectRows(FilteredColumns, each ([Region] <> null and [Region] <> 0)),
// Calculate average of desired columns
AverageS = List.Average(FilteredRows[S]),
AverageC = List.Average(FilteredRows[C]),
AverageO = List.Average(FilteredRows[O]),
AverageR = List.Average(FilteredRows[R]),
AverageE = List.Average(FilteredRows[E]),
AverageScoreOriginal = List.Average(FilteredRows[#"SCORE Original"]),
FileName = file[Name],
// Create a record for the average row
AverageRow = [Region="Average", Country="Average", S=AverageS, C=AverageC, O=AverageO, R=AverageR, E=AverageE, #"SCORE Original"=AverageScoreOriginal, #"SCORE Adjusted"=AverageScoreOriginal, #"Difference - Original to Adjusted"="0", Tier="High", DataSource = FileName],
// Append average row to the table
InsertAverageRow = Table.InsertRows(FilteredRows, Table.RowCount(FilteredRows), {AverageRow}),
AddDataSourceColumn = Table.AddColumn(InsertAverageRow, "DataSource", each FileName)
in
AddDataSourceColumn,
// Apply the ProcessFile function to each file in the SCORE folder
AddAverageRow = Table.AddColumn(SCORE, "Data", each ProcessFile(_)),
CombineTables = Table.Combine(AddAverageRow[Data]),
#"Renamed Columns" = Table.RenameColumns(CombineTables,{{"DataSource", "Data Category"}}),
#"Filtered Rows" = Table.SelectRows(#"Renamed Columns", each true)
in
Thanks in advance!
- Anonymous2 years ago
HI SUMESHKUMAR22,
As lbendlin said, you can try to use web contents optional parameter relative path to split your URL and move this dynamic part to the parameter to help it avoid the dynamic data source scenarios.
For the detail usage, you can refer to the below blog:
Using The RelativePath And Query Options With Web.Contents() In Power Query And Power BI M Code
Regards,
Xiaoxin Sheng
2 Replies
- lbendlinSuper User
This here is a forum where users help users, time permitting. For urgent requests contact a Microsoft partner near you.
Please refer to the documentation. It explains how to handle dynamic sources vis RelativePath and Query parameters. Web.Contents - PowerQuery M | Microsoft Learn
- AnonymousNot applicable
HI SUMESHKUMAR22,
As lbendlin said, you can try to use web contents optional parameter relative path to split your URL and move this dynamic part to the parameter to help it avoid the dynamic data source scenarios.
For the detail usage, you can refer to the below blog:
Using The RelativePath And Query Options With Web.Contents() In Power Query And Power BI M Code
Regards,
Xiaoxin Sheng