cancel
Showing results for 
Search instead for 
Did you mean: 
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
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors