MicroStrategy ONE
Adding a New Derived Metric
This example adds a new derived metric to the template, passing in the formula, name, position in the template, and alias (if any).
Code sample
1. WebReportInstance rInstance = rSource.getNewInstance(reportID);
2. WebReportManipulation rManipul = rInstance.getReportManipulator();
3. WebTemplate template = rInstance.getTemplate();
4. WebTemplateMetrics wtms = template.getTemplateMetrics();
5. WebTemplateMetric wtm = wtms.get(0);
6. int position = wtm.getPosition();
7. WebMetric metric = wtm.getMetric();
8. rInstance = rManipul.addDerivedMetric("[" + metric.getName() + "] + 2", position + 1, "TestAdd", "My Alias");
Explanation
Lines 1 and 2 create and retrieve the WebReportManipulation object required to add the derived metric. Lines 3-7 get the metric contained in the template. Line 6 gets the position of the metric so the new derived metric can be added after the base one. Line 8 calls the method to add a derived metric to the template. The first parameter is the formula for the derived metric, the second parameter is the metric position, the third is the name of the new derived metric, and the last parameter is the metric alias. Note that only the first three parameters are required.