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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
dobregon
Impactful Individual
Impactful Individual

TabularEditor Alter Expresion of Calculated Columns

Hi,

 

I have more than 50 calculated columns in a dataset that i need to replace some text inside the expression of each formula

For measures i have a query that i can use in the Tabular Editor that works very well and i'm looking for the same in for calculated columns

 

This example works for the measures selected 

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


and i'm trying to do the same with columns

/* For columns */
var FromString = "oldtext";
var ToString = "newtext";
foreach (var m in Selected.Columns)
    {
        m.Expression = m.Expression.Replace(FromString,ToString);
        /* Cycle over all measures in model and replaces the 
           FromString with the ToString */
    } 

The "Selected.Columns" works well, the issue is in the "m.Expression = m.Expression.Replace......"

The tabular show an error that Expression can't be used, the issue here is that i need to change the expression of the formula, maybe the function "expression" is not the correct one to modify columns, i'm asking if exist another function or what can i do to modify many columns expresion in one time

Can you help me?




Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)
2 REPLIES 2
vanessafvg
Super User
Super User

try 

 

/* For columns */
var FromString = "oldtext";
var ToString = "newtext";
foreach (var m in Selected.Columns)
    {
        m.Name= m.Name.Replace(FromString,ToString);
        /* Cycle over all measures in model and replaces the 
           FromString with the ToString */
    } 




If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




dobregon
Impactful Individual
Impactful Individual

@vanessafvg not working... this try to modify the name of the column, no the expression of the column that it is what i looking for.


thanks for the help in any case



Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.