创建表格组
脚本用途
该脚本会在 Tabular Editor 3 中创建默认表格组。
脚本
脚本标题
// Loop through all tables:
foreach(var table in Model.Tables)
{
if (table is CalculationGroupTable)
{
table.TableGroup = "Calculation Groups";
}
else if (!table.UsedInRelationships.Any() && table.Measures.Any(m => m.IsVisible))
{
// Tables containing visible measures, but no relationships to other tables
table.TableGroup = "Measure Groups";
}
else if (table.UsedInRelationships.All(r => r.FromTable == table) && table.UsedInRelationships.Any())
{
// Tables exclusively on the "many" side of relationships:
table.TableGroup = "Facts";
}
else if (!table.UsedInRelationships.Any() && table is CalculatedTable && !table.Measures.Any())
{
// Tables without any relationships, that are Calculated Tables and do not have measures:
table.TableGroup = "Parameter Tables";
}
else if (table.UsedInRelationships.Any(r => r.ToTable == table))
{
// Tables on the "one" side of relationships:
table.TableGroup = "Dimensions";
}
else
{
// All other tables:
table.TableGroup = "Misc";
}
}
说明
该脚本遍历模型中的所有表,并根据特定属性为其分配表格组。