Created
February 4, 2023 02:53
-
-
Save bjulius/971d8d386183a48d3c6132986704d7f4 to your computer and use it in GitHub Desktop.
C# Script to Automatically Create COUNTROWS Measures on Selected Tables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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