Forum Discussion
How do I replace a field/column/measure/reference throughout my pbi file
Hi,
In my report I have a field e.g. HC_field.
Based on this field I have created a measure HC_measure.
HC_measure is used in several visuals, and other calculations/measures in the report.
Later during my development, I have realised that a new field HC_field2 is more accurate for the HC_measure calculation.
How do I replace HC_field with HC_field2 in a way so all the references (i.e. measures and visuals) to HC_field will now refer to HC_field2 ?
In case I decide to create a new measure HC_measure2, and want all my visuals to use HC_measure2 instead of HC_measure - how do I do that ?
Many thanks
Anonymous,
You can replace the column name in all measures by using the following script in Tabular Editor (Advanced Scripting tab):
var FromString = "HC_field"; var ToString = "HC_field2"; foreach (var m in Model.AllMeasures) { m.Expression = m.Expression.Replace(FromString,ToString); }https://exceleratorbi.com.au/edit-replace-code-inside-all-dax-measures-using-tabular-editor/
I'm not aware of a way to programmatically swap fields in visuals.
1 Reply
- DataInsights
Super User
Anonymous,
You can replace the column name in all measures by using the following script in Tabular Editor (Advanced Scripting tab):
var FromString = "HC_field"; var ToString = "HC_field2"; foreach (var m in Model.AllMeasures) { m.Expression = m.Expression.Replace(FromString,ToString); }https://exceleratorbi.com.au/edit-replace-code-inside-all-dax-measures-using-tabular-editor/
I'm not aware of a way to programmatically swap fields in visuals.