exc aggr formulas special values

20
Aggregation and formula calculation with special values. Defining how values like NULL, ERROR and NOP shall be treated in calculations. SAP AG Version: 1.1 State: REVIEWED Target Audience: EXTERNAL Author: Sebastian Schrötel Additional content delivery: Stefan Dipper, Michael Wilking, Stefan Unnebrink, Silvia Bratz, Erich Marschall Valid for: BW 7.30 SP5+ and BW on HANA

Upload: konduru25

Post on 10-Nov-2015

71 views

Category:

Documents


1 download

DESCRIPTION

aggr

TRANSCRIPT

  • Aggregation and formula calculation with special values. Defining how values like NULL, ERROR and NOP shall be treated in calculations.

    SAP AG

    Version: 1.1

    State: REVIEWED

    Target Audience: EXTERNAL

    Author: Sebastian Schrtel

    Additional content delivery: Stefan Dipper, Michael Wilking, Stefan Unnebrink, Silvia Bratz, Erich Marschall

    Valid for: BW 7.30 SP5+ and BW on HANA

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    2

    TABLE OF CONTENTS

    1 STANDARD AND EXCEPTION AGGREGATION............................................................................ 3

    2 CURRENCY AGGREGATION .......................................................................................................... 9

    3 AGGREGATION AND SPECIAL VALUE SETS ............................................................................ 12

    4 FORMULA CALCULATION AND SPECIAL VALUE SETS .......................................................... 15

    LIST OF FIGURES Figure 1: Example Exception Aggregation ........................................................................................................ 6 Figure 2: Order of Aggregations in SAP BW ..................................................................................................... 7 Figure 3: Aggregation with different currencies ................................................................................................. 9 Figure 4: Currency aggregation with SUM ...................................................................................................... 10 Figure 5: Currency Aggregation with MIN ....................................................................................................... 11 Figure 6: Currency Aggregation with MAX ...................................................................................................... 11 Figure 7: Value sets with special values .......................................................................................................... 12

    LIST OF TABLES Table 1: (Exception) Aggregation rules in SAP BW 7.30 .................................................................................. 5 Table 2: Consulting OSS notes about aggregation ........................................................................................... 8 Table 3: Aggregation Matrix Part 1 .................................................................................................................. 13 Table 4: Aggregation Matrix Part 2 .................................................................................................................. 14 Table 5: Aggregation Matrix Part 3 .................................................................................................................. 14 Table 6: Important operators of formulas ........................................................................................................ 17 Table 7: Formula operators and special values .............................................................................................. 19

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    3

    1 STANDARD AND EXCEPTION AGGREGATION

    In the OLAP Processor of SAP Business Warehouse (BW) the defined key figures are aggregated. The aggregation behavior determines whether and how key figure values are aggregated in reports using the different characteristics or characteristic values. In order to calculate the values of key figures, the data from an InfoProvider has to be aggregated to the detail level of the query and formulas may also need to be calculated. The system has to aggregate using multiple characteristics. The basic form of aggregation is the so called standard aggregation. The standard aggregation can aggregate key figures with the following rules:

    Summation (SUM)

    Minimum (MIN)

    Maximum (MAX) The standard aggregation is independent from any specified dimensions/characteristics. So it aggregates over all characteristics not in the drill down, independent also from their order. The standard aggregation is the most common known aggregation behavior. In addition to the standard aggregation there is the exception aggregation. These are aggregation rules that are dependent from a characteristic. Exception aggregation determines how a restricted, calculated key figure or a formula is aggregated in the Analytic Engine with respect to one or several reference characteristics.

    1

    So to calculate the aggregate with an exception aggregation rule a characteristic is needed that defines the granularity on which basis the aggregation rule is applied. Up to this defined granularity for the exception aggregation the key figures are aggregated via the standard aggregation. So the exception aggregation is always an addition to the standard aggregation and not a replacement. A good example is the Average (AVG) aggregation rule. Average is always a sum divided by the number of entries. To determine the number of entries a data granularity needs to be defined to what the multidimensional data needs to be (standard) aggregated and counted afterwards. From a more business point of view, application cases for exception aggregation include warehouse stock, which cannot be added up over time, or counters that count the number of characteristic values for a certain characteristic. In general the different types of exception aggregation behavior for formulas and calculated key figures can be defined in the SAP NetWeaver Business Explorer Query Designer:

    1 Calculated key figures and formulas in BW 7.30 used with exception aggregation behave in the same way,

    at least to the greatest possible extent. Nevertheless in exceptional cases there could be differences in the query results.

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    4

    The different standard and exception aggregation rules available in SAP BW are explained in the following table:

    Abbreviation Aggregation rule Description

    AVG Average of All Values Average (all values) (AVG): The average of all values is displayed.

    AV0 Average of All Values < > 0 Average (value not equal to zero) (AV0): After drilling down according to the reference characteristic, the average of the column values not equal to zero is displayed in the results row.

    AV1 Average Weighted with Calendar Days

    Average (weighted with no. of days) (AV1): After drilling down according to the reference characteristic, the average of the column values weighted with the number of days is displayed in the results row.

    AV2 Average Weighted with Working Days

    Average (weighted with the number of workdays; factory calendar) (AV2): After drilling down according to the reference characteristic, the average of the column values weighted with the number of workdays is displayed in the results row.

    CNT Count All Values Counter (all values) (CNT): The number of existing values is displayed in the results row.

    CN0 Count All Values 0 Counter (value not equal to zero) (CN0): The number of values zero is displayed in the results row.

    FIR First Value First value (FIR): The first value in relation to the reference characteristic is displayed in the results row.

    LAS Last Value Last value (LAS): The last value in relation to the reference characteristic is displayed in the results row.

    MAX Maximum Maximum (MAX): The maximum value of all values displayed in this column is displayed in the results row.

    MIN Minimum Minimum (MIN): The minimum value of all values displayed in this column is displayed in the results row.

    NGA No Aggregation of Posted Nodes Along the Hierarchy

    No aggregation of postable nodes along the hierarchy (NGA).

    NHA No Aggregation Along the Hierarchy

    No aggregation along the hierarchy (NHA).

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    5

    Abbreviation Aggregation rule Description

    NO1 Exception If More Than One Record Occurs

    No aggregation (exception if more than one record arises) (NO1).

    NO2 Exception If More Than One Value Occurs

    No aggregation (exception if more than one value arises) (NO2).

    NOP Exception If More Than One Value 0 Occurs

    No aggregation (exception if more than one value 0) (NOP).

    STD Standard Deviation Standard deviation (STD): After drilling down according to the reference characteristic, the standard deviation of the displayed values is displayed in the results row.

    SUM Total Summation (SUM): The sum of all values displayed in this column is displayed in the results row.

    VAR Variance Variance (VAR): After drilling down according to the reference characteristic, the variance of the displayed values is displayed in the results row.

    Table 1: (Exception) Aggregation rules in SAP BW 7.30 In addition to the exception aggregation rules it is important to understand how exception aggregation works, and why it is needed. For this an example shall be used, to explain the need to refer to a characteristic in the aggregation rules.

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    6

    The example shows, that the order of the calculations is important to get a clear and correct result. This is why during aggregation, the OLAP Processor does first process the standard aggregation up to the requested level and afterwards the exception aggregation. An overview of the steps in SAP BW can be found in the following figure:

    The following example data is the basis for the example:

    Country Customer Month Net Sales

    US Peter January 100 $

    US Andi February 50 $

    DE Peter March 70 $

    DE Stefan January 30 $

    DE Andi March 20 $

    The data might exist on a much finer granularity (including more dimension/characteristics that are not used in this example). So this example data is treated as data already aggregated to the finest granularity needed in the query. The example query and its result would look like this:

    Country Net Sales Number of Customers

    AVG Sales per Customer

    Number of Customers in January

    DE 120 $ 3 40 $ 1

    US 150 $ 2 75 $ 1

    Total 270 $ 3 90 $ 2

    The query shows different types of aggregations and key figure types:

    1. Net Sales: This is a basic key figure with standard aggregation SUM, so the Total is a plain sum. Referring to the basis data for the example it is just the sum of all Net Sales column irrespective to any characteristic values.

    2. Number of Customers: This is a key figure with exception aggregation. To calculate the correct Total it is absolutely necessary to consider the characteristic values of the characteristic Customer. As customer Peter and Andi are both in the US and in DE there must be a count distinct with regard to column Customer in the basic data to calculate the right total.

    3. AVG Sales per Customer: This is a calculated key figure, the formula is defined as a division of Net Sales by Number of Customers. Here it is important that the formula is calculated on the correct subtotal level. The formula must be calculated after the aggregation, so on the detail rows, it takes the details as input, on the total rows other totals are the input.

    4. Number of Customers in January: This is a restricted key figure, it is the Number of Customers but restricted to the Month January. Here the data must be filtered before the aggregation and then like the Number of Customers key figure, the distinct with regard to the Customer column has to be considered.

    Figure 1: Example Exception Aggregation

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    7

    Figure 2: Order of Aggregations in SAP BW We have basically two agents in the aggregation process. The one that takes care of the aggregation of figures, the other one takes care of aggregation and handling of currencies and units. First the standard aggregation with the options SUM, MIN and MAX takes places. After that, the currency and unit conversion takes place. This is done then by the Currency/Unit Aggregation Handler. After the conversion the currency/unit aggregation that belongs to the standard aggregation step takes place. If exception aggregation is setup this is processed afterwards. Here we have options like SUM (default), MIN, MAX, AVG, FIRST, LAST, NOP, COUNT, STANDARD DEVIATION, VARIANCE, etc. As another aggregation step takes place, the currency/unit aggregation has to be done again. This is not an extra step like in the standard aggregation; here it is done during the exception aggregation. So during the aggregation the Aggregation Handler communicates with the Currency/Unit Handler. Next step is the formula calculation, if a formula was defined, of course. As during the exception aggregation, during the formula calculation, the currencies and units of the operands are brought together by the Currency/Unit Handler. Last, there is the possibility to execute exception aggregation upon the calculated formulas. This is basically the same step than the normal exception aggregation before, but operates on formula results. As before, the currency/unit aggregation is done during the formula exception aggregation. It has to be noted, that even in cases where the reference characteristic is not included in the query explicitly an aggregation is executed implicitly, using the reference characteristic. In other words, the standard aggregation does not aggregate over the reference characteristics of the later exception aggregation.

    Currency/Unit Aggregation HandlerAggregation

    Handler

    Standard Aggregation

    Currency or Unit Conversion

    Standard Currency/Unit Aggregation

    Exception Aggregation Currency/Unit Aggregation

    Formula Calculation Currency/Unit Handling

    Formula Exception Aggregation Currency/Unit Aggregation

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    8

    The system also reads the values at reference characteristic level from the underlying InfoProvider for the query. Due to this increased granularity, in particular when you are using reference characteristics with a large number of distinct characteristic values (instances), the system may transfer large quantities of data to the OLAP processor for further processing (e.g. The reference characteristic 0BPARTNER is used in the exception aggregation of a calculated key figure. 2,000,000 different characteristic values of 0BPARTNER are suitable for filtering the query. As a result, at least 2,000,000 records are transferred to the OLAP Processor). This means that even if the data volume that is displayed in the front end is rather small, the data volume that is to be read might be very large. As shown before, the standard aggregation does not aggregate over the currencies or units. This is done in extra steps, that has some implications on the data reading:

    First if a currency conversion was setup in the query definition the different data entries after the standard aggregation are converted into the target currency or unit.

    Afterwards the forced group-by currency or unit in the standard aggregation is removed. That means values with different currencies/units are aggregated. This happens with a set of rules described in the next chapter.

    More information on aggregation and exception aggregation can be found in the SAP Online Documentation:

    Aggregation in general: http://help.sap.com/saphelp_nw73/helpdata/en/4a/5dde624b3814aee10000000a42189b/frameset.htm

    Exception Aggregation: http://help.sap.com/saphelp_nw73/helpdata/en/82/f2dc37f0f12313e10000009b38f8cf/frameset.htm

    Query examples: http://help.sap.com/saphelp_nw73/helpdata/en/47/6078d2dcce6834e10000000a421937/frameset.htm

    Some interesting SAP notes about aggregation (to be used with caution, they may not be completely correct with regard to BW 7.30 anymore):

    Note Number Description

    460255 Information about aggregation, accumulation, results row

    152638 Aggregation settings in calculated key figures

    1151957 Interesting facts about the OLAP Processor/Analytic Engine

    1158831 Calculation before aggregation with BIA and aggregates

    379832 Calculating w/ variables w/ subst. from attrib. w/o char.

    676346 Zero suppression returns unexpected result

    973505 Calculation before the aggregation and formula variables

    Table 2: Consulting OSS notes about aggregation

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    9

    2 CURRENCY AGGREGATION

    In the chapter before the standard and exception aggregation was described. Figure 2: Order of Aggregations in SAP BW shows that between those two aggregation steps the currencies and units are handled. Besides the currency conversion the currency aggregation happens. That means values with different currencies or units assigned are aggregated into one result value. The next example shows some sample aggregations on the value sets V1 and V2, whereas the second set V2 consists of values with different currencies:

    Figure 3: Aggregation with different currencies From the example it can be seen, that if values with different currencies or units are aggregated and no unique currency or unit could be determined the result is *. This is the sign for mixed currency or unit. What must be mentioned here is that there are 3 types of aggregations with regard to currencies and units, so not all aggregations return *:

    1. Aggregation rules that are completely independent of any currencies or units: These are CNT and CN0. Nor in the input neither in the output of these aggregation rules currencies and units are considered.

    2. Aggregations that consider currencies and units in their input, but the result is not assigned to a currency or unit: This is the aggregation rule VAR (variant). The result has no currency or unit, but if the variance of two different currencies or units is calculated, it gives * as result.

    3. Aggregations that consider currencies in the input and the output: The result of the aggregation has also a reference to a currency and a unit. These are all other aggregation rules.

    In the aggregation rules that consider currencies and units there are defined rules when the result of the aggregation is a mixed currency/unit or the currency/unit can be clearly determined.

    Given is the following set: V1 = { (Luke, 10), (Obi-Wan, 12), (Anakin, 8) } This returns the following result for some different aggregations: SUM(V1) = 30 calculated as 10 + 12 + 8 CNT(V1) = 3 calculated as number of {Luke, Obi-Wan, Anakin} AVG(V1)= 10 calculated as SUM(V1)/CNT(V1) MIN(V1) = 8 calculated as the minimum value of {10, 12, 8} MAX(V1) = 12 calculated as the maximum value of {10, 12, 8} LAST(V1) = 8 calculated as the last value of the members {Luke, Obi-Wan, Anakin} is Obi-

    Wan, assuming lexical order If a set with mixed units/currencies is the basis: V2 = { (Luke, 10), (Leia, 15$) } SUM(V2) = * as the currencies differ, the sum cannot be calculated correctly. CNT(V2) = 2 calculated as the number of {Luke, Leia}, independent from currencies AVG(V2) = * as this is SUM(V2)/CNT(V2), and SUM(V2) = *, the average is also *

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    10

    First of all for the different aggregation rules the following currency aggregation rules apply:

    If several values not equal to 0 that have different currencies or units assigned are aggregated, the resulting currency/unit is *. If there is only one currency/unit, the result is that unique one.

    If there is a set of values that contains zeros, only the currencies/units assigned to non-zero key figure values are considered to determine if there is a unique currency/unit or not.

    If there is a set that only contains zeros, the resulting currency/unit is any of the provided ones.

    2

    So during the currency aggregation the OLAP processor builds two sets of currencies/units. One containing all currencies/units of non-zero key figure values (name it CUP) the other one containing all currencies/units of zero key figure values (name it CU0). If CUP only contains one entry, the result is clearly defined. If CUP contains more than one entry, the result is *. If CUP is an empty set, the result is any of CU0.

    Figure 4: Currency aggregation with SUM The rules from above are enhanced for the aggregation rules MIN and MAX. For MIN and MAX not only 2 sets of currencies/units are built, there is a third one. The first set contains all currencies/units for zero key figure values as with the other aggregation rules (CU0). The second set now contains all currencies/units of positive key figure values (CUP) and the third set contains all currencies/units of negative key figure values (CUN). For the aggregation rule MIN the following additional currency aggregation rules apply:

    If several values less than 0 that have different currencies or units assigned are aggregated, the resulting currency/unit is *. If there is only one currency/unit, the result is that unique one.

    If there is no key figure value in the set less than zero, the currencies/units of key figure values equal to zero are considered. If these currency/unit is unique, then it is taken as result, otherwise the resulting currency/unit is *.

    If there is no key figure value in the set to aggregate less or equal to zero, it is checked if all positive key figure values have a unique currency/unit assigned. If this is not the case and there are different currencies/units, the result is also *.

    2 In fact, it is not completely undefined which currency/unit is the resulting one, it is the one with the lowest

    SID (surrogate ID, technical ID of SAP BW).

    V2 = { (Luke, 10), (Leia, 15$) } SUM(V2) = * V3 = { (Leia, 15$), (Palpatine, 0) } SUM(V3) = 15$ V4 = { (Palpatine, 0), (Boba, 0$) } SUM(V4) = 0 ? (? Could be or $, dependent from the system)

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    11

    In an example this looks like this:

    Figure 5: Currency Aggregation with MIN In comparison to MIN, in the aggregation rule MAX the same handling is applied but the different subsets of positive, zero and negative values are considered in the opposite order from positive to negative. So the rules are:

    If several values greater than 0 that have different currencies or units assigned are aggregated, the resulting currency/unit is *. If there is only one currency/unit, the result is that unique one.

    If there is no key figure value in the set greater than zero, the currencies/units of key figure values equal to zero are considered. If these currency/unit is unique, then it is taken as result, otherwise the resulting currency/unit is *.

    If there is no key figure value in the set to aggregate greater or equal to zero, it is checked if all negative key figure values have a unique currency/unit assigned. If this is not the case and there are different currencies/units, the result is also *.

    Also an example for this rules:

    Figure 6: Currency Aggregation with MAX

    V5 = { (Han Solo, -12), (Chewbacca, 0), (Leia, 15$) } MIN(V5) = -12 V6 = { (Yoda, -61$), (Han Solo, -12), (Palpatine, 0) } MIN(V6) = * V7 = { (Palpatine, 0), (Leia, 15$), (R2D2, 28) } MIN(V7) = 0

    V5 = { (Han Solo, -12), (Chewbacca, 0), (Leia, 15$) } MAX(V5) = 15$ V6 = { (Yoda, -61$), (Han Solo, -12), (Palpatine, 0) } MAX(V6) = 0 V7 = { (Palpatine, 0), (Leia, 15$), (R2D2, 28) } MAX(V7) = *

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    12

    3 AGGREGATION AND SPECIAL VALUE SETS

    So far in this document value sets which contain valid values where described. If the value sets only contain homogeneous values the result is clear, that means all values have the same currency/unit assigned and no special values are part of the set. The rules that apply if there are valid values with different currencies or units where described in the chapter before. But there are even more complex value sets, which contain the values like 0, NULL, DIV0. These sets require a more complex understanding according to their behavior in a calculation. In the next example the result is not clear without any further rules.

    Figure 7: Value sets with special values The goal of this chapter is to explain how the different combinations between exception aggregation rules (AVG, AV0, etc.) and special value sets (e.g. { 0 }, { 0, DIV0 }, { 42, 13$ }, { 0, DIV0, 42, 13$ } ) behave. As the result of homogeneous value sets is easy to explain, here only the special value sets shall be considered. This chapter shall first describes the specific behavior and the results of standard and exception aggregation as used in basic key figures and formulas/calculated key figures (the so called formula exception aggregation). These aggregation rules shall be opposed to different value sets, which contain values that occur in very special situations (e.g. error or mixed currencies). There are basically 4 different value types groups to consider in the value sets:

    1. ERROR, the value is a result of an erroneous calculation, like DIV0 2. NOP, the value cannot be aggregation, result of aggregation rules NO1, NO2 and NOP 3. *, any valid value 4. NULL, no value exits

    The order in this enumeration also describes the priority how the values are considered in an aggregation. So the priority of the values in an aggregation are: First ERROR, then NOP, after that * (any valid value), last NULL. NOP is treated very similar to ERROR, so the following rules also apply:

    An aggregation that returns ERROR for the set {*, NULL, ERROR}, returns NOP for the set {*, NULL, NOP}, but ERROR for the set {*, NULL, NOP, ERROR}.

    A aggregation does not return ERROR for the set {*, NULL, ERROR}, it also does not return NOP for the set {*, NULL, NOP}. Examples are CN0, AV0, FIRST, LAST, CNT.

    V8 = { (R2D2, 28 ) (Palpatine, 0), (Boba, NULL), (Ackbar, 122$), (Jabba, DIV0) } AVG(V8) = ???

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    13

    In the following tables these priority rules are applied to some sample sets (in the columns, to simplify the display without characteristic members) and displayed in different aggregation rules (in the rows). Special non-cumulative related exception aggregation rules AV1 and AV2 are not displayed, as the reference of the time dimension is missing, they should anyway behave like AVG. The hierarchy exception aggregation rules NHA and NGA are discussed afterwards.

    B={ NULL } C={ 0 } D={ DIV0 } E={ 42 } F={ 0, DIV0 } G={ 0, 13$ }

    AVG NULL 0 DIV0 42 DIV0 6,5 $

    AV0 NULL 0 NULL 42 0 13 $

    CNT 0 1 1 1 2 2

    CN0 0 0 0 1 0 1

    FIR NULL 0 DIV0 42 0 0

    LAS NULL 0 DIV0 42 DIV0 13 $

    MAX NULL 0 DIV0 42 DIV0 13 $

    MIN NULL 0 DIV0 42 DIV0 0

    NO1 NULL 0 DIV0 42 DIV0 NOP

    NO2 NULL 0 DIV0 42 DIV0 NOP

    NOP NULL 0 DIV0 42 DIV0 13 $

    STD NULL 0 DIV0 0 DIV0 9,192 $

    SUM NULL 0 DIV0 42 DIV0 13 $

    VAR NULL 0 DIV0 0 DIV0 84,5

    Table 3: Aggregation Matrix Part 1

    H={DIV0, 42 } I={ 42, 13$ } J={ 42, -13$ } K={ 0, DIV0, 13$ } L={ 0, 42, 13$ }

    AVG DIV0 * * DIV0 *

    AV0 42 * * 13 $ *

    CNT 2 2 2 3 3

    CN0 1 2 2 1 2

    FIR DIV0 42 42 0 0

    LAS 42 13 $ -13 $ 13 $ 13 $

    MAX DIV0 * 42 DIV0 *

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    14

    H={DIV0, 42 } I={ 42, 13$ } J={ 42, -13$ } K={ 0, DIV0, 13$ } L={ 0, 42, 13$ }

    MIN DIV0 * -13 $ DIV0 0

    NO1 DIV0 NOP NOP DIV0 NOP

    NO2 DIV0 NOP NOP DIV0 NOP

    NOP DIV0 NOP NOP DIV0 NOP

    STD DIV0 * * DIV0 *

    SUM DIV0 * * DIV0 *

    VAR DIV0 * * DIV0 *

    Table 4: Aggregation Matrix Part 2

    M={ NOP } N={ 0, NOP } O={ NOP, 13$ } P={ DIV0, NOP, 13$ }

    AVG NOP NOP NOP DIV0

    AV0 NULL NULL 13 $ 13 $

    CNT 1 2 2 3

    CN0 0 0 1 1

    FIR NOP 0 NOP DIV0

    LAS NOP NOP 13 $ 13 $

    MAX NOP NOP NOP DIV0

    MIN NOP NOP NOP DIV0

    NO1 NOP NOP NOP DIV0

    NO2 NOP NOP NOP DIV0

    NOP NOP NOP NOP DIV0

    STD NOP NOP NOP DIV0

    SUM NOP NOP NOP DIV0

    VAR NOP NOP NOP DIV0

    Table 5: Aggregation Matrix Part 3

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    15

    What is missing in the tables are the hierarchy exception aggregation rules NGA and NHA. To understand how they work with regards to special values it must first be clear how they work. The hierarchy exception aggregation rules NHA and NGA are special aggregation rules to be used for hierarchies with posted nodes. Posted nodes are nodes that are not simply the aggregate of their children, but also have an own value that is added in the aggregate. It is possible to display the value part of a posted node as a child of that node, so that the display looks like it is a normal hierarchy. In the following example we have a normal hierarchy node (Node 1) and a Posted Node below with the value part Leaf 1. Leaf 1 can be displayed as child of the posted Node. Additionally the posted node has a real child, this is Leaf 2. Assuming sum aggregation the result would be as displayed in Keyfigure 1.

    Posted Node / Leaf 1

    Node 1

    Leaf 2

    Leaf 1

    Keyfigure 1 NGA(Keyfigure 1) NHA(Keyfigure 1)

    100

    100

    30

    70

    30

    30

    30

    70

    30

    30

    70

    If now exception aggregation NGA is applied upon Keyfigure 1, it has the result that the Posted node only has the value of the value part, that is Leaf 1. These value part is also the only one that is considered in upper level nodes, so Node 1 also has in the example the value of Leaf 1. That means NGA makes sure that a posted node is not the aggregate of its own value part plus its children, it is then just the value part. NHA works similarly, it additionally makes sure, that nodes without a posted value part, that are only the aggregates of their children, are displayed as NULL. So they have no value, if they are no posted nodes. With regards to special values like NULL, ERROR, NOP etc. the rules are quite easy. NGA and NHA do not define real aggregation rules, they define only that the posted part of a posted node shall be considered as the only value in the standard aggregation. So with NGA and NHA the value of a posted node is considered, no matter if it is a special value or not, and the rules of the standard aggregations SUM, MIN and MAX as shown in the part before are applied. 4 FORMULA CALCULATION AND SPECIAL VALUE SETS

    The same questions as for aggregation rules also apply to formulas. In formulas one or two operands are connected to an operator (therefore one-digit operators and two-digit operators exist). In the Front-Ends the formulas are often also called calculated key figures. Operands in a formula can be:

    The basic key figures, calculated key figures and restricted key figures from the relevant Info Provider

    All formula variables

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    16

    Operators in a formula that are available in BW 7.30 are:

    Basic functions

    Percentage functions

    Data functions

    Mathematical functions

    Trigonometric functions

    Boolean operators Some important operators are shown in the following table:

    Operator Operator name Operator Type Description

    + Plus Basic functions Adds one operand to another

    - Minus Basic functions Subtracts one operand from another

    * Multiply Basic functions Multiplies one operand with another

    /, DIV Divide Basic functions Divides one operand by a second one

    MOD Modulo Mathematical functions

    Gives the rest of a division of two operands

    ** Power Basic functions Calculates one operand power another

    % Percentage Variance Percentage Functions This gives the percentage variance between operand 1 and operand 2. It is identical to: Formula 100 * ( - ) / abs( ).

    %A Percentage Share Percentage Functions This gives the percentage share of operand 1 and operand 2. It is identical to formula 100 * / abs().

    %CT Percentage Share of Result

    Percentage Functions This shows how high the percentage share is, with regard to the result. The result is the outcome of aggregating the second highest results level (interim result).

    %GT Percentage Share of Overall Result

    Percentage Functions This shows how high the percentage share is with regard to the overall result. The overall result is the outcome of aggregating the highest results level. Dynamic filters (filters that were not specified in the Query Designer) also play a role in calculating the overall result.

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    17

    Operator Operator name Operator Type Description

    %RT Percentage Share of Query Result

    Percentage Functions This is similar to %GT. Unlike the process for calculating the overall result, dynamic filters are not used in the calculation of the query result. This means that the calculation always normalizes to the same value, irrespective of the filter status and the navigational state.

    COUNT Counter Data Functions Returns value = 1 if operand 0, otherwise 0

    DELTA Delta Data Functions Returns value = 1 if operand = 0, otherwise 0

    NDIV0 No DIV0 Data Functions NDIV0 (x): Equals 0 when divided by 0, otherwise x

    NODIM Values Without Dimensions

    Data Functions Returns purely numerical values of the operand and suppresses units and currencies.

    NOERR No Error Data Functions NOERR (x): Is equal to 0 for undefined calculations, otherwise x

    MIN Minium Mathematical functions

    Returns the smaller one of two operand

    MAX Maximum Mathematical functions

    Returns the bigger one of two operand

    Table 6: Important operators of formulas More information can be found in the Online Help:

    Defining Formulas: http://help.sap.com/saphelp_nw73/helpdata/en/71/0aec3b6e011341e10000000a114084/frameset.htm

    Defining Calculated Key Figures: http://help.sap.com/saphelp_nw73/helpdata/en/71/0aec3b6e011341e10000000a114084/frameset.htm

    There are also some consulting SAP notes that give additional information to formulas (to be used with caution, they may not be completely correct with regard to BW 7.30 anymore):

    Note Number Description

    794006 Display of zero or 0.00 with certain formula operators

    1385580 How does a formula variable with a replacement path work?

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    18

    Calculations with null values and other exceptional values in formulas are differentiated more precisely in 7.30. This chapter shall now describe basic rules that apply to formulas regarding special values in BW 7.30.

    3

    In the following:

    NULL, represents the null value;

    DIV0, the result of a division using a value of 0;

    ERROR, the error indicator;

    NOP, the indicator that no aggregation is possible;

    W, any valid value; and * for any value;

    O1 is an one-digit operator (like NODIM, NOERR etc.)

    and O2 is a two-digit operator (like +, -, * etc.). Some more information to NOP: NOP is the result of the NO1, NO2 and NOP aggregation rules, and says, that there is no aggregation possible. See also the exception aggregation chapters. NOP as result of an operation (on an inhomogeneous value set) is located in the priority rules between NULL and ERROR:

    1. ERROR/DIV0 2. NOP 3. NULL or normal value depending on operation.

    The rules that apply to formulas are:

    NOERR( ERROR ) = 0, NDIV0(DIV0) = 0, O1(NULL) = NULL and O1(ERROR) = ERROR for all remaining one-digit operators O1. For NOP also NOERR(NOP) = 0, NDIV0(NOP) = NOP, O1(NOP) = NOP for all remaining one-digit operators O1. This rule basically says, that all operators with only one parameter pass through DIV0/NULL/ERROR/NOP values.

    O2(NULL,NULL) = NULL, O2(ERROR,*)= ERROR and O2(*,ERROR) = ERROR for all two-digit operators. This rule basically says, that ERROR (including DIV0) is dominant in all operations, and all operations with only NULL input result in NULL.

    O2(ERROR,NOP)= ERROR and O2( {value OR NULL} ,NOP) = NOP for all two-digit operators. This rule basically says, that DIV0/ERROR is dominant to NOP, and NOP is dominant to all other values.

    O2(NULL,W) = O2(0,W) and O2(W,NULL) = O2(W,0), with the exception of the following combinations that return NULL as result: NULL * W, W * NULL, NULL / W, NULL %A W, NULL %_A W, NULL %RT W, NULL %GT W, NULL %CT W, NULL ** W, NULL DIV W, NULL MOD W.

    Because the OLAP Processor in BW has the defined behavior, that adding a structure element must not change the content of all other structure elements, the OLAP has to handle Division by Zero and Overflows without just aborting the query. So if one cell contains a division by zero or another error, the other cells must not be affected at all. As DIV0 is a more specific subset of ERROR, DIV0 and ERROR behave the same if combined with other parameter values in operations. The behavior of DIV0 and ERROR within binary operations is unspecified and may be dependent on the two-digit operator O2:

    O2(DIV0, ERROR) = DIV0 or ERROR

    O2(ERROR, DIV0) = DIV0 or ERROR DIV0 might be given some precedence, so the more specific DIV0 might win. But overall the behavior is not clearly defined.

    3 See also OSS Note 794006

  • AGGREGATION AND FORMULA CALCULATION WITH SPECIAL VALUES

    19

    The complete behavior and all the rules can be found in the following table:

    Operator Left Operand Right Operand

    Y NULL NOP DIV0 / ERROR

    +, -

    X X op Y X

    NOP

    DIV0 / ERROR

    NULL Y (-Y)4 NULL

    NOP NOP DIV0 / ERROR DIV0 / ERROR

    *

    X X op Y NULL

    NOP NULL NULL NULL NOP NOP

    DIV0 / ERROR DIV0 / ERROR

    /, DIV, MOD

    X X op Y5 DIV0

    NOP NULL NULL NULL NOP NOP

    6 DIV0

    DIV0 / ERROR DIV0 / ERROR

    Power (**)

    X X ** Y 1 NOP NULL NULL NULL

    NOP NOP DIV0 / ERROR DIV0 / ERROR

    %, %_A, %_RT, %_GT, %_CT

    X X op Y X op 0

    NOP NULL NULL NULL NOP NOP

    DIV0 / ERROR DIV0 / ERROR

    other operations, e.g. MIN, MAX

    X X op Y X op 0

    NOP NULL 0 op Y NULL NOP NOP

    DIV0 / ERROR DIV0 / ERROR Table 7: Formula operators and special values

    4 The result of NULL + Y is Y, NULL Y is Y.

    5 Can return DIV0 if Y is 0.

    6 Can return DIV0 if Y is 0.

  • 2012 SAP AG. All rights reserved.

    SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP

    BusinessObjects Explorer, StreamWork, SAP HANA, and other SAP

    products and services mentioned herein as well as their respective

    logos are trademarks or registered trademarks of SAP AG in Germany

    and other countries.

    Business Objects and the Business Objects logo, BusinessObjects,

    Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and

    other Business Objects products and services mentioned herein as

    well as their respective logos are trademarks or registered trademarks

    of Business Objects Software Ltd. Business Objects is an SAP

    company.

    Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL

    Anywhere, and other Sybase products and services mentioned herein

    as well as their respective logos are trademarks or registered

    trademarks of Sybase Inc. Sybase is an SAP company.

    Crossgate, m@gic EDDY, B2B 360, and B2B 360 Services are

    registered trademarks of Crossgate AG in Germany and other

    countries. Crossgate is an SAP company.

    All other product and service names mentioned are the trademarks of

    their respective companies. Data contained in this document serves

    informational purposes only. National product specifications may vary.

    These materials are subject to change without notice. These materials

    are provided by SAP AG and its affiliated companies ("SAP Group")

    for informational purposes only, without representation or warranty of

    any kind, and SAP Group shall not be liable for errors or omissions

    with respect to the materials. The only warranties for SAP Group

    products and services are those that are set forth in the express

    warranty statements accompanying such products and services, if

    any. Nothing herein should be construed as constituting an additional

    warranty.

    www.sap.com