Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PBI-DataVizzle/21b8e96fe6d8bf5faf4872b36498a0a9 to your computer and use it in GitHub Desktop.
Save PBI-DataVizzle/21b8e96fe6d8bf5faf4872b36498a0a9 to your computer and use it in GitHub Desktop.
Tabular editor scripts for Power BI
//This gist contains useful tabular editor scripts.
// script for automating repetitive measures from selected columns. Thanks Alex!
// GitHub https://github.com/itsnotaboutthecell/Power-BI-Sessions/tree/master/An%20Introduction%20to%20Tabular%20Editor
// #GiveCreditForCode
foreach(var column in Selected.Columns) {
column.Table.AddMeasure(
column.Name + " (Median|Benchmark)", //this line is for the measure name
"MEDIAN(" + column.DaxObjectFullName + " )", // This line is for the DAX
"Measures New" // This line is for the measure display folder
);
};
// Thanks Antriksh Sharma! Code based on : https://www.youtube.com/watch?v=C6WgYUE7ZAw
// This script will create a file with all the DAX measurs and DAX tables within the model
// #GiveCreditForCode
string result = "";
string newLine = "\r\n";
string measureSeparator = "----------------------------------------";
string tableSeparator = "*-*-*-*-*-*-*-*-*-*-*-*-*";
foreach(Table t in Model.Tables) {
if (t.Measures.Count>0){
result = newLine + result + tableSeparator + newLine + t.Name + newLine + tableSeparator + newLine + newLine;
foreach(Measure m in t.Measures){
result = measureSeparator + newLine + result + m.DaxObjectName + " = ";
result = result +m.Expression + newLine + measureSeparator + newLine;
}
}
}
//result.Output();
SaveFile("C:\\Users\\Path\\Measures.txt", result.ToString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment