Adding a Measure

This page provides a description of how we can add a measure. It features an example in which we use a new ‘TestNumber’ field as a measure. For a walk through on how to added a field to an existing data store please see the documentation HERE. The techniques employed are generic examples that can be extended, adapted and repeated for any use case that we need. In all cases, we make minimal changes to the Reference Implementation.

To add a field as a measure we need to make two modifications to the OlapModelConfig class inside /cvarc-starter/src/main/java/com/activeviam/cvarc/starter/cfg/impl/OlapModelConfig.java.

Step 1 - Modifying Manager Description

In the managerDescription() method we want to append the managerDesc by adding the following lines above the return statement for the method.

Prerequisite information: To learn more about navigating the managerDesc please CLICK HERE.

            AggregatedMeasureDescription testNumber = new AggregatedMeasureDescription("TestNumber Measure", "TestNumber", "SUM"); // we can construct a measure with ("Measure's Name", "FieldName, "Aggregation")

//      Alternatively we can create a new AggregatedMeasure with no attributes and set them using the helper methods provided as shown below
//          AggregatedMeasureDescription testNumber = new AggregatedMeasureDescription();
//          testNumber.setFolder("Technical");
//          testNumber.setName("TestNumber Measure");                                      
//          testNumber.setFieldName("TestNumber");
//          testNumber.setPreProcessedAggregation("SUM");

            testNumber.setFormatter(CVAConfigProperties.FORMATTER_PLUGIN__WHOLE_NUMBER);

            managerDesc.getSchemas().get(1).getActivePivotSchemaDescription().getActivePivotInstanceDescriptions().
                    get(0).getActivePivotDescription().getMeasuresDescription().getValues().add(testNumber);

            return managerDesc;

Step 2 - Modifying Schema

Modify our Cube’s schema so that the Field can be found and set to be a measure, in this case our modifications will be made in the createSASchemaSelectionDescription() method.

.withField(SharedDataStoreNames.TRADE_DESCRIPTION_IS_BA_ELIGIBLE, SAStoreNames.SA_BASE_TO_TRADE_DESCRIPTION_REF+"/"+SharedDataStoreNames.TRADE_DESCRIPTION_IS_BA_ELIGIBLE)
.withField(SharedDataStoreNames.TRADE_DESCRIPTION_IS_SA_ELIGIBLE,  SAStoreNames.SA_BASE_TO_TRADE_DESCRIPTION_REF+"/"+SharedDataStoreNames.TRADE_DESCRIPTION_IS_SA_ELIGIBLE)
.withField(BAStoreNames.NETTING_SET_CAPITAL_TREATMENT, SharedDataStoreNames.CAPITAL_TREATMENT_TO_SA_BASE_STORE_REF+"/"+BAStoreNames.NETTING_SET_CAPITAL_TREATMENT)
.withField(SharedDataStoreNames.IS_CARVED_OUT,SharedDataStoreNames.CAPITAL_TREATMENT_TO_SA_BASE_STORE_REF+"/"+SharedDataStoreNames.IS_CARVED_OUT)
.withField(SAStoreNames.SA_DOMAIN)
.withField("TestNumber", SAStoreNames.SA_BASE_TO_VEGA_REF+"/TestNumber")       // here we describe the path from the base store to the field we wish to expose as a measure
.build();