EducationSoftwareStrategy.com
StrategyCommunity

Knowledge Base

Product

Community

Knowledge Base

TopicsBrowse ArticlesDeveloper Zone

Product

Download SoftwareProduct DocumentationSecurity Hub

Education

Tutorial VideosSolution GalleryEducation courses

Community

GuidelinesGrandmastersEvents
x_social-icon_white.svglinkedin_social-icon_white.svg
Strategy logoCommunity

© Strategy Inc. All Rights Reserved.

LegalTerms of UsePrivacy Policy
  1. Home
  2. Topics

KB4755: How to use a metric as a subtotal for another metric in MicroStrategy Intelliegence Server SDK 9.x


Community Admin

• Strategy


MicroStrategy Desktop does not provide an interface to achieve this; therefore, custom code using the MicroStrategy Intelliegence Server SDK needs to be developed. This document provides an example on how to do so in Visual Basic (VB).

Strategy Desktop does not provide an interface to achieve this; therefore, custom code using the Strategy Intelliegence Server SDK needs to be developed. This document provides an example on how to do so in Visual Basic (VB).
 

ka04W000001MKxTQAW_0EM440000002H1X.gif

 
Create the following metrics (the '<' and '>' symbols denote the dimensionality of a metric):


M1: SUM(F1)
M2: SUM(F2)
M3: SUM(F2) <A2>
M4: SUM(F2) <A1>
S1_A2: SUM(M1 * M2) / SUM(M3)
S2_A1: SUM(M1 * M2) / SUM(M4)



Notice how the subtotals are defined as sums of the metrics (nested aggregation).
For this example, the following display is required:

ka04W000001MKxTQAW_0EM440000002H1W.gif

Note that S2_A2 is used as the subtotal for M2 at the A2 level and S2_A1 is used as the subtotal for M2 at the A1 level.
 
Sample of code in VB using the Strategy SDK is shown below. This procedure must have a Strategy 9.x project registered as a Project Source. In this example, the source name 'METRIC CHANGE PROJECT SOURCE' that holds the 'METRIC CHANGE' project, is being used.


Private Sub Change_Metric ()    
    Dim strErrMsg 
    Screen.MousePointer = vbHourglass 
    'Adjust the following to your environment: 
    Const DataSourceName As String = "METRIC CHANGE PROJECT SOURCE" 
    Const Login As String = "Administrator" 
    Const Password As String = "" 
    Const ProjectName As String = "METRIC CHANGE" 
    Const Metric_FullName As String = "S2_A1" 
    
    Dim DataSource As New DSSDataSource 
    Dim DataSourceList As DSSDataSourceEnumerator 
    
    Set DataSourceList = New DSSDataSourceEnumerator 
    DataSourceList.LoadFromRegistry 
    
    Set DataSource = DataSourceList.Item(DataSourceName) 
    DataSource.AuthMode = DssAuthStandard 
    DataSource.Login = Login 
    DataSource.Passwd = Password 
    DataSource.Init 
    
    Dim ProjectList As DSSDataSourceEnumerator 
    Dim Project As DSSDataSource 
    
    Set ProjectList = DataSource.Enumerator 
    'The following line will set the project to be METRIC CHANGE_1 
    Set Project = ProjectList.Item(ProjectName & "_1") 
    'MsgBox Project.Name 
    Project.Init 
    
    Dim Session As IDSSSession 
    Dim ObjectSource As IDSSSource 
    Set Session = Project.CreateSession 
    Set ObjectSource = Session.Component(DssRoleObjectSource) 
    
    Dim SearchFolder As IDSSFolder 
    Dim SearchObj As IDSSSearch 
    Set SearchObj = ObjectSource.NewObject(DssTypeSearch) 
    SearchObj.NamePattern = Metric_FullName 
    SearchObj.Types.Add (DssTypeMetric) 
    Set SearchFolder = SearchObj.Execute 
    
    Dim Metric As IDSSMetric 
    Set Metric = SearchFolder.Item(1) 
    
    'MsgBox Metric.Info.Name 
    
    'Change metric to subtotal: 
    Metric.MetricType = DssMetricSubtotal 
    'Get the folder of objects embedded in this metric: 
    Dim Metric_Embedded As IDSSEmbeddedFolder 
    'Objects that exist as embedded in this metric: 
    Set Metric_Embedded = Metric.Info.Embedded 
    'Metric_02_Embedded(IDSSFolder) contains 1 metric, 2 agg metrics
    
    
    'Get the expression tree of the first aggmetric 
    Dim AggMetric As IDSSObjectInfo 
    Dim AggMetric_Exp As IDSSExpression 
    
    Set AggMetric = Metric_Embedded.Item(3) 
    'Using VB object watch, we can check that the third element of 
    AggMetric.Special.Expression.Item contains a reference to the metric 
    that this metric will be subtotal of (M2):

    'Item(1) = Metric_01
    'Item(2) = AggMetric_01
    'Item(3) = AggMetric_02 <-- has the reference to M2
    
    'For Each OI in Metric_Embedded.Item
    '   do something
    'End For Each 
        
    Set AggMetric_Exp = AggMetric.Special.Expression
    Dim CurrentNode As IDSSNode 
    'Remove node with reference to M2 
    Set CurrentNode = AggMetric_Exp.Root.Child.Child.Child.Next 
    CurrentNode.Remove 

    'Add a DssNodeMe in its place 
    Set CurrentNode = AggMetric_Exp.Root.Child.Child 
    CurrentNode.Add (DssNodeMe) 

    'Save the metric 
    Metric.Info.Save 
    MsgBox "Done." 
    Screen.MousePointer = vbArrow 
    Exit Sub 
ErrCatcher:
    MsgBox "Error: " & strErrMsg 
    Screen.MousePointer = vbArrow

 

The example provided in this document is provided “as-is” and user has read the following customization warning:
ADDITIONAL INFORMATION:
The Strategy SDK allows you to customize several Strategy products and extend and integrate the Strategy business intelligence functionality into other applications. However, before changing the way Strategy products look or behave, it is helpful to understand how the application is built. For more information regarding the Strategy products or the process of customizing Strategy products, please refer to Strategy Developer Zone (https://developer.microstrategy.com).
To access the Strategy Developer Zone, you must have access to the Strategy Knowledge Base, you must have purchased the Strategy SDK, and you must be current on your Strategy maintenance agreement. If you are a US-based business and believe that you satisfy all three of these conditions but you do not have access to the Strategy Developer Zone, please contact Strategy Technical Support at support@microstrategy.com or at (703) 848-8700. If you are an international business, please contact Strategy Technical Support at the appropriate email address or phone number found at https://www.microstrategy.com/us/services/support/contact.
CUSTOMIZATION WARNING:
This customization is provided as a convenience to Strategy users and is only directly applicable to the version stated. While this code may apply to other releases directly, Strategy Technical Support makes no guarantees that the code provided will apply to any future or previous builds. In the event of a code change in future builds, Strategy Technical Support makes no guarantee that an updated version of this particular customization will be provided. In the event of a code change in future builds, Strategy may not be able to provide additional code on this matter even though this customization is provided at this time for this specific build. For enhancements to this customization or to incorporate similar functionality into other versions, contact your Account Executive to inquire about Strategy Consulting assistance.


Comment

0 comments

Details

Knowledge Article

Published:

March 31, 2017

Last Updated:

March 31, 2017