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
ChetanK004
Regular Visitor

Column created in a table appears in another table

Hi,

 

I am using Microsoft.AnalysisServices.Tabular to alter the dataset via C# code.

i have a table called Table A and there is another Table Called Table A Custom, Now when i try to add a column in Table A Custom it also appears on Table A some how, I have debugged the whole case and have seen that through code it is only updating a single table Table A Custom.

 

// tables contain ['Table A Custom','Table B Custom']
for( tableName in tables){               
var pbiTable = database.Model.Tables
                                        .FirstOrDefault(x => x.Name.Equals(tableName, StringComparison.OrdinalIgnoreCase));
                        var pbiColumns = pbiTable?.Columns;
                        var fieldsToAdd = getFieldsFromDb();
                            fieldsToAdd.ForEach(field => AddField(field.Name, field.DataType, pbiColumns));
}

// Function to add the column
        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,
                LineageTag = fieldName + "-" + Guid.NewGuid(),
            };
            pbiColumns.Add(newColumn);
        }

Note: This behaviour is intermittent, does not happen everytime i try to do, but it usually happens when i freshly publish the dataset to service and try to add fields to the table via code. also note sometimes the fields do not appear quickly but appears after a refresh to that dataset. i am unable to find the root cause for the same

4 REPLIES 4
v-priyankata
Community Support
Community Support

Hi @ChetanK004 

Thank you for reaching out to the Microsoft Fabric Forum Community.

@Zanqueta Thanks for the inputs.

I hope the information provided by user was helpful. If you still have questions, please don't hesitate to reach out to the community.

 

ChetanK004
Regular Visitor

Hi @Zanqueta , Thanks for the response, For the below root causes

Root Causes

  1. 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
  2. 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
 
Save and refresh properly
After adding columns i do perform the database.Model.SaveChanges()
 
There is One more observation i found is regarding RequestRefresh(RefreshType.Full);
 
Before i used to call an RefreshDatasetInGroupAsync REST API by passing the modified tables as a parmeters to DatasetRefreshRequest and perform a datataset refresh after called database.Model.SaveChanges()
 
But i recently found out that  RequestRefresh is a better option if we are changing the scheme of dataset (like adding / delete columns), Which should be called before database.Model.SaveChanges()
 
Now i had a scenario where i added few columns to the dataset and performed dataset refresh with below refresh mode
1) Model.RequestRefresh(RefreshType.Full) This performed action and i observerd an entry in dataset refresh history in the pbi service, every time i ran the code everytime i saw an entry of type Via XMLA Endpoint
2) Table.RequestRefresh(RefreshType.Full) This performed action sometimes, i observed it added an entry to the dataset refresh history in this 2 cases
1) If the dataset was published freshly and we ran the code, it did a refresh and added entry 
2) If dataset had changes ( adding / deleting columns via code) for the first time and we ran the code , it did a refresh and added entry , there after if we did any changes to dataset, it niether refreshed nor created an entry in the history, is this inteded?
 
I did look around some articles where it was mentioned that each RequestRefresh will add an entry in the history either its model / table, is there anything am missing?
 

 

 

 

That's it for me. Seems the rigth direction, just have pay attention to:
 
Make sure each table is instantiated independently:

 
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.

 

If this answer was helpful in any way, I’d be happy to receive a 👍 and the joy of seeing a DAX measure work for the first time without needing yet another FILTER.
Please mark it as the accepted solution. This helps other community members find the quickest path and saves them from another endless loop 🌀.

Zanqueta
Solution Sage
Solution Sage

Hi @ChetanK004,

 

 

This behaviour is related to how Microsoft.AnalysisServices.Tabular manages object references in the Tabular Object Model (TOM). When you add a column to a table, the change is applied to the in-memory model, and then persisted when you call Model.SaveChanges(). If columns appear in another table, it usually indicates one of the following:

 

Please, look at steps bellow an try:

Root Causes

  1. 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.
    • This can happen if the tables were cloned or created from the same object without deep copying.
  2. Model refresh behaviour
    • After publishing, the service may apply schema changes during refresh, merging metadata from the original source and your custom changes.
    • If the original table and the custom table share the same Source or LineageTag logic, the refresh can propagate columns unexpectedly.
  3. Intermittent timing
    • When changes are made immediately after publishing, the model may not have fully synchronised with the service, causing delayed appearance of columns.

Recommended Fixes

 

Ensure unique references

Before adding columns, confirm that you are working with the correct table object:
 
 
var pbiTable = database.Model.Tables
    .FirstOrDefault(x => x.Name.Equals(tableName, StringComparison.OrdinalIgnoreCase));

if (pbiTable == null)
    throw new Exception($"Table {tableName} not found.");

var pbiColumns = pbiTable.Columns;
 
Avoid reusing pbiColumns across iterations.
 
Save and refresh properly
After adding columns:
 
database.Model.SaveChanges();
 
 
If this answer was helpful in any way, I would be pleased to receive a 👍, as well as the satisfaction of seeing a DAX measure work for the first time without needing yet another FILTER.
Please mark it as the accepted solution. This helps other community members find the quickest path and saves them from another endless loop 🌀.
 

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.