Fix Visuals or Replace Measures in Power BI Reports using pbi-tools
About the Role
Fix visuals or replace measures in Power BI reports using pbi-tools without redoing formatting and prevent reports from breaking when measures are moved to other tables.
Context - The Problem
- Renaming fields (including measures) or moving measures to another table breaks visuals, resulting in the "grey box of death."
- Power BI identifies fields by name, not a unique identifier, so renaming or moving measures requires manual fixes in each visual.
- Replacing measures in multiple visuals (e.g., due to stakeholder changes) is time-consuming, especially when formatting must be reapplied.
- Modifying the underlying DAX expression isn’t always ideal, particularly in self-service or personalized visuals.
Solution: pbi-tools
pbi-tools is an external tool that decompiles .pbix files to access the report's "Layout" definition (source code). It allows programmatic fixes for broken measure references while preserving formatting.
- Decompile the .pbix file using pbi-tools extract to access the report's JSON-based layout.
- Replace incorrect field/table references in the visuals' config.json files.
- Recompile the .pbix file using pbi-tools compile to restore functionality.
Note: This method does not work if the .pbix file is encrypted (e.g., with sensitivity labels).
Why Visuals Break
Visuals reference fields in three ways within the layout JSON:
- Full fields: TableName.ColumnName or TableName.MeasureName (e.g., in queryRef or Name keys).
- Tables: TableName only (e.g., in Entity keys), used even for measures.
- Fields: FieldName or MeasureName only (e.g., in Property keys).
Renaming or moving measures breaks visuals because the references no longer match the model. For measures, the TableName prefix in Entity keys must be updated, but the TableName.MeasureName syntax is not required.
Fixing Visuals: Replacing References
- Replace incorrect field/table names in the JSON files using find-and-replace or regex for specificity.
- Avoid unintended changes by targeting specific keys/values (e.g., Entity, queryRef).
- Test recompiled reports to ensure formatting and functionality are preserved, especially for complex visuals.
Examples
- Renaming a measure: Changed [Sales vs. PY (%)] to [Delivered Revenue vs. PY (%)] and fixed references via JSON edits.
- Moving a measure: Moved [Orders vs. PY (%)] from the Orders table to the Customers table and updated references.
Quick Steps
- Download pbi-tools CLI and add it to your PATH.
- Decompile the .pbix file: pbi-tools extract [path].
- Replace broken field/table references in the visuals' JSON files (e.g., config.json).
- Recompile the .pbix: pbi-tools compile [output-folder].
- Reopen the .pbix file to verify changes.
For complex visuals, test thoroughly to ensure all formatting and references are correctly updated.