Forum Discussion
Column created in a table appears in another table
- 7 months ago
Hi v-priyankata ,
We had a procedure on dataset that would bind the columns they created dynamically to table or custom table, we had to point it to custom table in that procedure which could be one of the root cause of the issue,(So the code was trying to add to new table and the procedure pointed to old table and when we refreshed the dataset it would appear in 2 tables) anyways we are currently not facing the duplicate column issue for now after we changed the procedure to point to new table, but we are not sure if it would happen anytime again.
Hi Zanqueta , Thanks for the response, For the below root causes
Root Causes
- Shared or cloned references
- If pbiColumns is referencing the same ColumnCollection object for both tables due to incorrect initialisation or reuse of objects, adding a column will affect both - The base Table is not in the loop, also i tried debugging the code which only looped once for the custom table but the fields appeared in both tables.
- This can happen if the tables were cloned or created from the same object without deep copying. - Probably this might be a candidate, Although we created the table using TOM not via code, so we will re-build the dataset by creating new custom field from scratch
- Model refresh behaviour
- If the original table and the custom table share the same Source or LineageTag logic, the refresh can propagate columns unexpectedly. - This can be a candidate too, but i when i add new column i dont specify the Lineage Tag, i believe Power BI creates one by default
var pbiTable = database.Model.Tables
.FirstOrDefault(x => x.Name.Equals(tableName, StringComparison.OrdinalIgnoreCase));
if (pbiTable == null)
throw new Exception($"Table {tableName} not found.");Add columns safely
private void AddField(string fieldName, DataType fieldType, ColumnCollection pbiColumns)
{
if (pbiColumns == null) return;
var newColumn = new Microsoft.AnalysisServices.Tabular.DataColumn
{
Name = fieldName,
DataType = fieldType,
SourceColumn = fieldName
};
pbiColumns.Add(newColumn);Use the recomended refresh method and order For schema changes:
Model.RequestRefresh(RefreshType.Full);
database.Model.SaveChanges();
- Prefer Model.RequestRefresh(RefreshType.Full) over Table.RequestRefresh for structural changes.
- This ensures the dataset refresh is properly registered in the service.
References:
Model.RequestRefresh Method (Microsoft.AnalysisServices.Tabular) | Microsoft Learn
Please, let me know if it worked.