As I just started out with c# Scripts in Tabular Editor 3
TLDR:
How can I select all measures from multiple table by hardcoding in a c# script? So that no manual selection is needed.
The goal is to then apply a new FormatString to all the measures included in these tables
===
so instead of
foreach(var m in (Selected.Table.Measures)
{…
I would need something lile
var m = {Model.Tables[“Measures Table 1”].Measures, Model.Tables[“Measures Table 2”].Measures Model.Tables[“Measures Table 2”].Measures};
or Model.Tables[“Measures Table 1”, “Measures Table 2”, “Measures Table 3”].Measures
but I couldn’t find the correct syntax to work in TE3
If the table names contain a specific text, you could try something like this:
foreach( var t in Model.Tables.Where(t => t.Name.Contains("Table")) ){
foreach( var m in t.Measures ){
{
m.FormatString = "0";
}
}
}
If you omit this part, it would apply the FormatString to all measures in all tables. .Where(t => t.Name.Contains("Table"))
.
If you want to provide a list with table names to work through:
var tNames = new List<string>() { "Table1", "Table2" };
foreach(var t in Model.Tables){
for (int i = 0; i < tNames.Count; ++i)
if (t.Name == tNames[i]){
foreach( var m in t.Measures ){
{
m.FormatString = "0";
}
}
}
}
.
Or if you wanted to work table by table, update the var tName = “Table1” that’s the part in between the double quotes to run it for that table.
var tName = "Table1";
foreach( var t in Model.Tables.Where( t => t.Name == tName ) ){
foreach( var m in t.Measures ){
{
m.FormatString = "0";
}
}
}