Question

Im writing c# application using Microsoft.AnalysisServices in which I would like to retreive MeasureGroups measures from my Cube.

Here is the code:

Server server = new Server();
  server.Connect(serverName);
  Database database = server.Databases.FindByName(databaseName);
  Cube cube = database.Cubes.FindByName(cubeName);

Here I have my Cube and then:

    MeasureGroup sampleMeasureGroup = cube.MeasureGroups[0];

Then I can get measures associated with sampleMeasureGroup by simply:

    var measures = sampleMeasureGroup.Measures;

But in this case I dont get Calculated measures, only standard ones. Is there any way I can get calculated measures ?

Was it helpful?

Solution

You can use the low level API which accesses the schema rowsets like this:

AdomdClient.AdomdRestrictionCollection restrColl = new AdomdClient.AdomdRestrictionCollection();
restrColl.Add("CUBE_NAME", cube.Name);
DataSet ds = clientConn.GetSchemaDataSet("MDSCHEMA_MEASURES", restrColl);
foreach(DataRow row in ds.Tables[0].Rows) {
    string expr = row.Field<string>("EXPRESSION");
    if (string.IsNullOrEmpty(expr)) {
        // measure is a physical measure
    } else {
        // measure is a calculated measure, and 'expr' is its definition
    }
    // use other columns like MEASURE_NAME, MEASURE_UNIQUE_NAME, DATA_TYPE,
    // DEFAULT_FORMAT_STRING ... as you need them
}

The MDSCHEMA_MEASURES rowset lists all measures contained in the cube, and is documented here: http://technet.microsoft.com/en-us/library/ms126250.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top