Scripting Magic with C# in Tabular Editor and Semantic Model for Power BI
I don't think I need to introduce Tabular Editor - but I would like to showcase specific and concrete examples on how C# Scripts can "pimp my model" as ??Alexander Korn and Data Goblins provide initial setup but also assistance when maintaining and developing the semantic model ??
Beware, that creating tables and columns is unsupported when using Tabular Editor as external tool in Power BI Desktop. You need to develop the model from scratch inside Tabular Editor.
Make sure you know how to do it manually and the purpose behind, before you automate the entire process - that's my personal opinion.
For each new project or semantic model, I see recurring requests that we need somewhat of the following for initial setup and for each deployment. What if we could use a standard .PBIT or C# script to help us and make it consistent across the organisation on how we create the inital tables and naming convention ??
Initial Setup:
For each deployment:
From tables into table groups:
领英推荐
Table groups, which I'm particular excited about. However it unfortunately don't propogate to Power BI Desktop, but it creates dynamically groups for the table kind.
//Create Table Groups
// 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";
}
}
Resources for all the C# Scripts and next step:
Enjoy ??
Thank you for reading my article, hope you enjoyed it. Comment or provide some input is much appreciated.
?? Hi my name is David Kofod Hanna, Senior Advisor and Consultant at twoday and my aim is to guide self-service Power BI developers for more enterprise managable concepts in a consumable and practical way - because I have been on that journey for years, and still is...
Senior BI Consultant @ HICO | Ex-Microsoft | ActionableReporting.com
3 个月Great article and thanks for the mention. Totally agree, grouping tables is an underrated feature. Glad we have it with TE3. I found an idea related to this. Tabular Editor let's keep up the good work pushing Power BI to improve. Maybe just like it was with Calc Groups, always one step ahead? ?? https://ideas.fabric.microsoft.com/ideas/idea/?ideaid=9267b1d4-cf7d-4c67-8c2f-54b5e3544457