MicroStrategy ONE
Adding a New Percent-to-total Metric
This example creates a new percent-to-total metric and adds it to the template.
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. WebMetric metric = wtm.getMetric();
7. WebPercentToTotalMetric pttmetr = rManipul.getNewPercentToTotalMetric(metric);
8. pttmetr.setAxesBitMap(EnumDSSXMLAxesBitMap.DssXmlAxisRowsBit);
9. rInstance = rManipul.addPercentToTotalMetric(pttmetr);
Explanation
Lines 1 and 2 create and retrieve the WebReportManipulation object required to add the derived metric. Lines 3-6 get the metric from the template. Line 7 creates a WebPercentToTotalMetric using the base metric. Line 8 is used to set the attributes on this metric object. Line 9 adds the percent-to-total metric to the template by calling the addPercentToTotalMetric method on the report manipulation object. The WebPercentToTotalMetric object is the parameter for this method.