Introducing Measures

Objective

After completing this lesson, you will be able to describe how measures are used in a query

Measures

Measures represent the numerical attributes of a business transaction or an event. They often represent monetary values such as flight cost or quantities, such as occupied seats. Measures can also represent general numbers such as number of children.

Measures are usually aggregated across one or more dimensions to give them meaning. For example, occupied seats by airline for each year.

Measures often originate from the columns of source tables where their data type is a numerical type such as decimal or integer.

Measures can also be generated from formulas, for example seats available = seats max - seats occupied.

Reference to Currency / Unit

Measures in a cube view often reference a currency or a unit of measurement. This reference is introduced via the following annotations positioned above the measure:

  • @Semantics.amount.currencyCode: 'MyCurrency'
  • @Semantics.quantity.unitOfMeasure: 'MyUnit'

For these annotations, you specify the field that provides the currency or unit of measurement.

These annotations are not required for measures that do not relate to a currency or a unit of measurement.

Virtual Currency / Unit

For every new measure that you introduce in an analytical query, you should define a virtual field for the currency or unit. This is necessary since during the calculation the currency or unit can change implicitly.

  • virtual MyVirtualCurrency: abap.cuky - in case the measure is of type amount
  • virtual MyVirtualUnit: abap.unit - in case the measure is of type quantity
  • virtual MyVirtualComplexUnit: dd_cds_calculated_unit - in case the measure is a formula with a complex unit (for example, EURO / piece)

Decimal Shift

In many formulas it is not possible to use operands of type CURR. Therefore, it is necessary to first convert the field to type DECFLOAT using the function CURR_TO_DECFLOAT_AMOUNT. However, it is not possible to use this function in each formula so therefore it is recommended to use this function when defining the base measure or restricted measure.

  • CURR_TO_DECFLOAT_AMOUNT( AmountInCompanyCodeCurrency ) as AmountInCompanyCodeCurrency

You should take care to always define formulas using the alias field $projection.fieldname. If the field is only needed in a formula then you can hide it with @Consumption.hidden: true.

Measure Settings

For each measure, there are many settings that influence how it functions and how it is displayed. These settings can be defined via the annotations.

SettingDescription

Visibility

By default all measures are shown – but you can influence the visibility:

@UI.hidden: true – measure is hidden from the initial query result but the business user can choose to display it

@Consumption.hidden: true - measure is hidden and cannot be displayed by the business user but can be used for further calculations

Scaling

@AnalyticsDetails.query.scaling: n

n is an Integer Number from 0 to 9. Numbers will be scaled by a factor of 10**n.

Decimals

@AnalyticsDetails.query.decimals: n

n is an Integer Number from 0 to 9. Numbers will be displayed with n decimals.

Change Sign

To flip the sign of a measure, the annotation @AnalyticsDetails.query.reverseSign: true can be used.

Log in to track your progress & complete quizzes