Creating Metrics in Bulk

Here’s a quick Command Manager script I wrote this morning when I had to create 60 metrics off of 60 Facts.  They were all simple Sum(Fact) Metrics.

  //list all metrics in the project  
   String sProjectName = "PROJECT NAME";
   String sFactFolder = "\Schema Objects\Facts\Folder";
   String sMetricFolder = "\Public Objects\Metrics\Folder";
    ResultSet oFacts = executeCapture("LIST ALL FACTS IN FOLDER '" + sFactFolder + "' FOR PROJECT '" + sProjectName + "';");  
    while (!oFacts.isEof() )
      //get name and path of this metric to list properties
      String sFactName = oFacts.getFieldValueString(DisplayPropertyEnum.NAME);            
      //get properties of each metric
      execute("CREATE METRIC "" + sFactName + "" IN FOLDER "" + sMetricFolder + "" EXPRESSION 'sum([" + sFactName + "])' ON PROJECT "" + sProjectName + "";");

To run this script, fire up Command Manager and click New Procedure.  Paste it in, update the variables at the top, and save some time.  In order to run it, you have to enter your connection information in the Test Information tab on the right side of the procedure editor.

Using this script I was able to create all 60 metrics in about 10 seconds!

You may also like...