Skip to content

Instantly share code, notes, and snippets.

@bjulius
Created February 4, 2023 02:53
Show Gist options
  • Save bjulius/971d8d386183a48d3c6132986704d7f4 to your computer and use it in GitHub Desktop.
Save bjulius/971d8d386183a48d3c6132986704d7f4 to your computer and use it in GitHub Desktop.
C# Script to Automatically Create COUNTROWS Measures on Selected Tables
/*
* Title: Auto-generate COUNTROWS measures from tables
*
* Author: Edgar Walther, twitter.com/edgarwalther
*
* This script, when executed, will loop through the currently selected tables,
* creating one COUNTROWS measure for each table.
*/
// Loop through all currently selected tables:
foreach(var table in Selected.Tables) {
var newMeasure = table.AddMeasure(
"# Rows in " + table.Name, // Name
"COUNTROWS(" + table.DaxObjectFullName + ")" // DAX expression
);
// Set the format string on the new measure:
newMeasure.FormatString = "0";
// Provide some documentation:
newMeasure.Description = "This measure is the number of rows in table " + table.DaxObjectFullName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment