Forum Discussion
Aaron_C
2 years agoFrequent Visitor
Tabular Editor 2, C# Script - Movng created measures to a different table
Hello all, Trying to accomplish what in theory seems like a simple mechanic, but I have not found a way to accomplish this in any of the resources for generates DAX measures via C# Scripts in Tabu...
- 2 years ago
Hi,
Would this do the trick?var measureTable = Model.Tables["Measure Table"]; // Replace "Measure Table" with your desired table name foreach(var c in Selected.Columns) { var newMeasure = measureTable.AddMeasure( "Sum of " + c.Name, // Name "SUM(" + c.DaxObjectFullName + ")", // DAX expression c.DisplayFolder // Display Folder ); // Set the format string on the new measure: newMeasure.FormatString = "0.00"; // Provide some documentation: newMeasure.Description = "This measure is the sum of column " + c.DaxObjectFullName; // Optionally, hide the base column: c.IsHidden = true; }
mariussve1
2 years agoSolution Sage
Hi,
Would this do the trick?
var measureTable = Model.Tables["Measure Table"]; // Replace "Measure Table" with your desired table name
foreach(var c in Selected.Columns)
{
var newMeasure = measureTable.AddMeasure(
"Sum of " + c.Name, // Name
"SUM(" + c.DaxObjectFullName + ")", // DAX expression
c.DisplayFolder // Display Folder
);
// Set the format string on the new measure:
newMeasure.FormatString = "0.00";
// Provide some documentation:
newMeasure.Description = "This measure is the sum of column " + c.DaxObjectFullName;
// Optionally, hide the base column:
c.IsHidden = true;
}
- Aaron_C2 years agoFrequent Visitor
You godsend!
That's worth writing a small blog on now 🙂
Thank you!