Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dbernabefdez
Frequent Visitor

How to replace text in Bulk for Calculated Columns -- Tabular Editor

Hi Community

 

I´ve found this script to change in bulk measures using Tabular Editor:


var FromString = "Text1";
var ToString = "Text2";

foreach(var c in Selected.Measures)
{
c.Expression = c.Expression.Replace(FromString,ToString);
/* Cycle over all measures in model and replaces the
FromString with the ToString */
}

 

 

It works pretty good for measures but dont seem to work for Calculated Columns because I get the following error.

 

dbernabefdez_0-1674819884560.png

 

 

 

Does anyone know how to solve this issue???

 

Thanks in advance

 

Best

1 ACCEPTED SOLUTION
LQuedas
Resolver II
Resolver II

Hey @dbernabefdez 

 

After looking at the documentation and doing an example you should try the following code

 

var FromString = "Text1";
var ToString = "Text2";

foreach(var c in Selected.CalculatedColumns)
{
c.Expression = c.Expression.Replace(FromString,ToString);
/* Cycle over all measures in model and replaces the
FromString with the ToString */
}

 

Hope it works for you.

 

Cheers, LQ

 

 

 

View solution in original post

2 REPLIES 2
LQuedas
Resolver II
Resolver II

Hey @dbernabefdez 

 

After looking at the documentation and doing an example you should try the following code

 

var FromString = "Text1";
var ToString = "Text2";

foreach(var c in Selected.CalculatedColumns)
{
c.Expression = c.Expression.Replace(FromString,ToString);
/* Cycle over all measures in model and replaces the
FromString with the ToString */
}

 

Hope it works for you.

 

Cheers, LQ

 

 

 

WOUU incredible!!!! Works great

 

I was making the mistake of using ""foreach(var c in Selected.Columns)"" instead of ""foreach(var c in Selected.CalculatedColumns)""

 

Thank you so much for your help

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.