Forum Discussion
Simple Way to Handle Column Renames in Power BI?
- 1 year ago
Hey,
I think it should be enough if you add a step in power query to rename the columns using the mapping table, you should try to add this step
= Table.RenameColumns(PreviousStep, List.Zip({MappingTable[OldColumnName], MappingTable[NewColumnName]}), MissingField.Ignore)I created an example PBIX file for you (attacched). Feel free to check it out.
I have a Power BI solution with reports connected to Databricks tables.
The backend team is planning to change the naming conventions, meaning all table and column names will be updated.
This will cause issues in the frontend (visuals, measures, and applied filters will break).
I already have mapping tables for all the changes.
Is there a way to apply these changes automatically to my reports, for example with a script that updates everything?
Thanks in advance!
Hello !
You can re-bind but don’t rename (no visual/measures break)
What you can change ? You need to point each table query to the new Databricks table name (and schema/catalog if that changed) and for each model column, switch its SourceColumn to the new physical column name.
What you do not change ?the table name and column name in the model and visuals, relationships, measures, roles, calc groups, perspectives keep working.
You can go to Tabular Editor (Desktop model or via XMLA on Premium/PPU) and use Advanced Scripting with a mapping you already have.
// Tabular Editor (Advanced Scripting) – bulk rebind to renamed Databricks objects.
// 1) Fill these maps from your mapping tables:
var tableMap = new System.Collections.Generic.Dictionary<string,string> {
// {"PhysicalOldTableName","PhysicalNewTableName"}
// {"sales_order_hdr","sales_order_header"}
};
var columnMap = new System.Collections.Generic.Dictionary<string,System.Collections.Generic.Dictionary<string,string>> {
// {"ModelTableName" : { "PhysicalOldColumn" : "PhysicalNewColumn", ... } }
// ModelTableName = table name as it appears in Power BI (friendly name)
// {"Sales Orders", new(){ {"ord_id","order_id"}, {"cust_id","customer_id"} } }
};
// 2) Update partition queries (M) to point to the new physical table names:
foreach (var t in Model.Tables.ToList())
{
foreach (var p in t.Partitions)
{
var msrc=p.Source as MPartitionSource;
if (msrc != null)
{
var expr = msrc.Expression ?? "";
foreach (var kvp in tableMap)
{
// naive replace: good if your M references native table names.
expr = expr.Replace(kvp.Key, kvp.Value);
}
msrc.Expression = expr;
}
// (If you use native SQL queries instead of M, detect and replace there similarly.)
}
}
// 3) Rebind columns to new physical column names (keep friendly names unchanged):
foreach (var t in Model.Tables)
{
if (!columnMap.ContainsKey(t.Name)) continue;
var map = columnMap[t.Name];
foreach (var c in t.Columns.OfType<DataColumn>())
{
var oldPhys = c.SourceColumn;
if (oldPhys != null && map.TryGetValue(oldPhys, out var newPhys))
{
c.SourceColumn = newPhys; // <-- rebind
}
}
}
// 4) Optional: if your Databricks catalog/schema changed, update data sourc here.
// 5) Save. Then refresh a small table to smoke test before full refresh.
You run this once against the shared dataset (or your PBIX model) because you don’t rename the model fields and your reports keep working.
If you can touch the lakehouseor Unity Catalog, you create views with the old names that select the new columns:
CREATE OR REPLACE VIEW old_schema.sales_order_hdr AS SELECT order_id AS ord_id, customer_id AS cust_id, ... FROM new_schema.sales_order_header;
and point PBI to those views then migrate at your pace to the new physical names.