kf after before aggregation

42
BW OLAP Aggregation Lothar Schubert, BW RIG SAP Labs America, LLC March 2003

Upload: sapernydape

Post on 04-Nov-2014

106 views

Category:

Documents


0 download

DESCRIPTION

KF After Before Aggregation

TRANSCRIPT

Page 1: KF After Before Aggregation

BW OLAPAggregation

Lothar Schubert, BW RIG

SAP Labs America, LLC

March 2003

Page 2: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 2

No

Dat

a

Wit

h D

ata

Introduction – The Role of the OLAP Engine

Master Data

Basic InfoCube

MultiProvider

InfoSet

Info

Pro

vid

er Interface

ODS Object

OLAP Engine

Business

Explorer

Virtual InfoCube

Page 3: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 3

Overview

KF/CKF Properties and Exception Aggregation OLAP Processor – Under the Hood Case Study “Revenue Calculation” Calculation with “Reference to Characteristic” Formula Collision Percentage and Summary Functions

Page 4: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 4

Overview

KF/CKF Properties and Exception Aggregation OLAP Processor – Under the Hood Case Study “Revenue Calculation” Calculation with “Reference to Characteristic” Formula Collision Percentage and Summary Functions

Page 5: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 5

Exception Aggregation Settings on KF Level

Department Headcount Month HeadcountD1 100 1/3/03 160D2 80 2/3/03 180Result 180 << SUM Result 170 << AVG, with regards to Month

Example:

Page 6: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 6

Exception Aggregation - Counting

CNT: Counting of all values with respect to reference characteristic

Business Scenario: How many different materials does a customer have "Open Orders" for?

Drilldown

Page 7: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 7

Exception Aggregation - Average

Calculation Steps Aggregate values

using standard aggregation

Aggregate values using exception aggregation

Drill-down by Material explains result

309 = ( 225 + 20 + 630 + 360) / 4

AVG: Average of all values with respect to reference characteristic

Business Scenario: Average "Open Order Qty" per Material

Drilldown

Page 8: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 8

Exception Aggregation – First & Last Value

FIR, LAS Exception Aggregation (see note 310791) Should only be used with non-cumulative key figures Generally use time characteristic as reference characteristic If being used for cumulative key figures:

Completeness of values with respect to reference characteristic necessary.

If being used with non time char. as reference characteristic: Sorting is done ascending according to key (internal presentation)

Plant Posting Date Value1 06/15/03 251 06/16/03 152 06/15/03 20

Plant Posting Date Value1 15 << last posted value concerning plant 1 - 6/162 20 << last posted value concerning plant 2 - 6/15

Result 15 << last posted value concerning plant 1+2 - 6/16

Cumulative InfoCube Example:

Page 9: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 9

Key Figure (Selection, Formula) Properties

Note, that the those calculations always act on displayed data only

Page 10: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 10

CKF Aggregation Behavior “Assignment”

Complexity “Assignment”, if of type”= KF” Exception Aggregation Behavior (and reference) can be set freely Default is setting of underlying Basic KF

PROPERTIES

Page 11: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 11

CKF Aggregation Behavior “Simple”

Complexity “Simple”, if exclusively operands of same aggregation, where operands can have complexity “Simple” themselves (KF, Constants, CKF)

Before / After Aggregation can be set

Page 12: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 12

CKF Aggregation Behavior “Complex”

Complexity “Complex” applies to all other cases “Enhance” options are not ready for input (“greyed out”) Calculation always occurs after aggregation

Page 13: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 13

Overview

KF/CKF Properties and Exception Aggregation OLAP Processor – Under the Hood Case Study “Revenue Calculation” Calculation with “Reference to Characteristic” Formula Collision Percentage and Summary Functions

Page 14: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 14

OLAP Initialization

Check Authorizations Is it ok to execute query? Is it ok to read data from InfoProvider?

Process Variables Exit for global variables (before variable input) is processed Prompt for variable input Exit for global variables (that failed before input) is processed Variable values are distributed to fixed filter, hierarchy settings, dynamic

filter, conditions & exceptions, formulas, …

Initialize OLAP Processor Notify Presentation hierarchies (if used) Check time stamps for OLAP cache (and release respective Ids)

Page 15: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 15

OLAP Processor in Detail I

1. OLAP request arrives from client Request for free characteristics Request for Dynamic filters

2. Include additional characteristics necessary for aggregation / calculation. For example:

Exception aggregation Elimination of internal business volume Formula variables with replacement from attribute value, if used in

restricted key figure (RKF)

3. Check authorization for navigation state (where necessary)4. Search for Cached data in OLAP Cache

Skip steps 5-14 and go to step 15 if cached data is found

Page 16: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 16

OLAP Processor in Detail II

5. Request data from database6. Receive data from database

Data arrives in blocks up to 1000 rows Data is still separated by InfoProvider (in case of MultiProvider) Data is still separated by Aggregate of InfoCube Data is still separated into cumulative and non-cumulative key figures

7. Call BusinessAdd-In “Virtual Characteristics and Key Figures”8. Check global filters (if not already done by database)9. Add attributes values for variables with replacement from attribute

used in RKF10.Separate data according to RKFs and selections in structure

elements11.Perform currency translation12.Process sums and calculated key figures (CKFs)

“before aggregation”13.Aggregate data to detail level (see 2.)14.Perform Hierarchy aggregation…

if

OL

AP

Cac

he

is N

OT

uti

lize

d …

Page 17: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 17

OLAP Processor in Detail III

15.Filter and aggregate data (result lines)

16.Perform Elimination of Internal Business Volume (where applicable)

17.Perform Exception aggregation

18.Execute Currency/Unit aggregation

19.Add attributes values for variables with replacement from attribute used in formulas

20.Calculate formulas and CKFs “after aggregation” Check Currencies/Units

21.Perform List Operations, e.g. Sort Conditions Local calculations/aggregations Cumulated values

Page 18: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 18

Overview

KF/CKF Properties and Exception Aggregation OLAP Processor – Under the Hood Case Study “Revenue Calculation” Calculation with “Reference to Characteristic” Formula Collision Percentage and Summary Functions

Page 19: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 19

OLAP Engine, w/ Example of Revenue Calculation

KH_ATTRIBUTE_REPLACEMENT

Calendar yearKey Figures Quantity, CKF (QU * PR)KHMAT2

KHMAT2 Quantity CKF (QU * PR)M1 11.000 PC $ 110.00000 PCM2 15.000 PC $ 300.00000 PCOverall Result 26.000 PC $ 410.00000 PC

KH_ATTRIBUTE_REPLACEMENT

Calendar yearKey Figures Quantity, CKF (QU * PR)KHMAT2

Calendar year Quantity CKF (QU * PR)2001 12.000 PC $ 190.00000 PC2002 14.000 PC $ 220.00000 PCOverall Result 26.000 PC $ 410.00000 PC

InfoCube contains field Quantity Material Attribute contains field Price Revenue should be calculated by the OLAP Processor

Page 20: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 20

Data Model (1)

InfoCube Definition

Key Figure “Quantity”

Page 21: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 21

Data Model (2)

InfoCube Definition

“Price” Attributes

Page 22: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 22

Data

InfoCube

Material Master

Page 23: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 23

Formula Variable, based on Attribute Value

Create

Page 24: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 24

1. Try: Usage in Formula

KHMAT2 Quantity 'KHF1' * 'Quantity'M1 11.000 PC $ 110.00000 PCM2 15.000 PC $ 300.00000 PCOverall Result 26.000 PC X

Calendar year Quantity 'KHF1' * 'Quantity'2001 12.000 PC X2002 14.000 PC XOverall Result 26.000 PC X

Formula Editor

Page 25: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 25

2. Try: RKF, “Before Aggregation” (1)

CreateProperties

“Price”

Page 26: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 26

2. Try: RKF, “Before Aggregation” (2)

KHMAT2 Quantity KHK1_BEFOREM1 11.000 PC $ 20.00M2 15.000 PC $ 40.00Overall Result 26.000 PC $ 60.00

Calendar year Quantity KHK1_BEFORE2001 12.000 PC $ 30.002002 14.000 PC $ 30.00Overall Result 26.000 PC $ 60.00

Quantity = AVG, CKF, Before

Material Year Quantity PriceM1 2001 5 10M1 2001 6 10M2 2002 7 20M2 2002

Material Year Quantity PriceM1 11 20M2 15 40Result 26 60

Query DefinitionOLAP ProcessorExplanation

Page 27: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 27

3. Try: RKF, “After Aggregation”

KHMAT2 Quantity KHK1_AFTERM1 11.000 PC $ 10.00M2 15.000 PC $ 20.00Overall Result 26.000 PC $ 30.00

Calendar year Quantity KHK1_AFTER2001 12.000 PC $ 30.002002 14.000 PC $ 30.00Overall Result 26.000 PC $ 30.00

Quantity = SUM, CKF, After

Material Year Quantity PriceM1 2001 11 M2 2001 15

Material Year Quantity PriceM1 11 10M2 15 20Result 26 30

OLAP ProcessorExplanation

Page 28: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 28

4. Try: Formula, using CKF from before

KHMAT2 Quantity KHK1_AFTER 'Quantity' * 'KHK1_AFTER'M1 11.000 PC $ 10.00 $ 110.00000 PCM2 15.000 PC $ 20.00 $ 300.00000 PCOverall Result 26.000 PC $ 30.00 $ 780.00000 PC

Calendar year Quantity KHK1_AFTER 'Quantity' * 'KHK1_AFTER'2001 12.000 PC $ 30.00 $ 360.00000 PC2002 14.000 PC $ 30.00 $ 420.00000 PCOverall Result 26.000 PC $ 30.00 $ 780.00000 PC

Quantity = SUM, CKF, After Qu * Pr = Formula

Material Year Quantity Price Qu * PrM1 2001 5 M1 2002 6 M2 2001 7 M2 2002 8

Material Year Quantity Price Qu * Pr2001 12 30 3602002 14 30 420

Result 26 30 780

Quantity = SUM, CKF, After Qu * Pr = Formula

Material Year Quantity Price Qu * PrM1 2001 5 M1 2002 6 M2 2001 7 M2 2002 8

Material Year Quantity Price Qu * PrM1 11 10M2 15 20Result 26 30

Material Year Quantity Price Qu * PrM1 11 10 110M2 15 20 300Result 26 30 780

OLAP ProcessorExplanation

Page 29: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 29

5. Try: Revenue Calculation within RKF (1)

Page 30: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 30

5. Try: Revenue Calculation within RKF (2)

KHMAT2 Quantity CKF (QU * PR)M1 11.000 PC $ 110.00000 PCM2 15.000 PC $ 300.00000 PCOverall Result 26.000 PC $ 410.00000 PC

Calendar year Quantity CKF (QU * PR)2001 12.000 PC $ 190.00000 PC2002 14.000 PC $ 220.00000 PCOverall Result 26.000 PC $ 410.00000 PC

Quantity = SUM, CKF, After Qu * Pr = CKF

Material Year Quantity Price Qu * PrM1 2001 5 M1 2002 6 M2 2001 7 M2 2002 8

Material Year Quantity Price Qu * PrM1 11 10 110M2 15 20 300Result 26 30 410

OLAP ProcessorExplanation

Page 31: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 31

Some additional Notes

Be careful when using multiple aggregation types (see example below, for a mix of “before” and “after”).

‘Allowed’ in CKF: = KF * Attribute, e.g. = Quantity * Price = KF / Attribute, e.g. = Quantity / Price

‘Not allowed’ in CKF (i.e. leading potentially to unwanted results): = Attribute, e.g. = Price = Attribute / KF e.g. = Price / Quantity

Performance impacts, in case of ‘before aggregation’ All required records have to be read into OLAP processor (and processed individually) No aggregates cannot be applied

In case of MultiProviders… Datasets are processed individually per InfoProvider first

In case of Inventory (non cumulative) InfoCubes… ‘Before aggregation’ does not allow formulas with mix of KF types

Always consider calculation already in UpdateRules (see Note 379832)

KHMAT2 Quantity KHK1_BEFORE KHK1_AFTER CKF (QU * PR)M1 11.000 PC $ 20.00 $ 20.00 $ 110.00000 PCM2 15.000 PC $ 40.00 $ 40.00 $ 300.00000 PCOverall Result 26.000 PC $ 60.00 $ 60.00 $ 410.00000 PC

Calendar year Quantity KHK1_BEFORE KHK1_AFTER CKF (QU * PR)2001 12.000 PC $ 30.00 $ 30.00 $ 190.00000 PC2002 14.000 PC $ 30.00 $ 30.00 $ 220.00000 PCOverall Result 26.000 PC $ 60.00 $ 60.00 $ 410.00000 PC

Page 32: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 32

Overview

KF/CKF Properties and Exception Aggregation OLAP Processor – Under the Hood Case Study “Revenue Calculation” Calculation with “Reference to Characteristic” Formula Collision Percentage and Summary Functions

Page 33: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 33

Motivation

Mostly, the OLAP first aggregates data and then applies calculations

Sometimes you would like to change this sequence(however you do not want to use “before aggregation” for all characteristics combinations, due to performance reasons)

Example Cube Data:

Here, it would be ok to aggregate first by Material and Month, but it’s required to perform the calculation prior to aggregation on Order.

Price per Unit

Page 34: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 34

“After Aggregation” would deliver wrong results

Page 35: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 35

Usage of “Reference to Characteristic” (1)

Page 36: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 36

Usage of “Reference to Characteristic” (3)

This attribute is available for every Characteristic (also 2.0b/2.1c) Also here: Consider performance impacts

Perhaps calculation can already occur in Update Rules.

Page 37: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 37

Overview

KF/CKF Properties and Exception Aggregation OLAP Processor – Under the Hood Case Study “Revenue Calculation” Calculation with “Reference to Characteristic” Formula Collision Percentage and Summary Functions

Page 38: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 38

Formula Collision

Quantity Quantity 'Quantity' * 'Quantity'2001 12.000 PC 12.000 PC 144.00000 PC 2̂2002 14.000 PC 14.000 PC 196.00000 PC 2̂Summary 26 PC 26 PC 676.00000 PC 2̂

Quantity Quantity 'Quantity' * 'Quantity'2001 12.000 PC 12.000 PC 144.00000 PC 2̂2002 14.000 PC 14.000 PC 196.00000 PC 2̂Summary 26 PC 26 PC 676.00000 PC 2̂

Quantity Quantity 'Quantity' * 'Quantity'2001 12.000 PC 12.000 PC 144.00000 PC 2̂2002 14.000 PC 14.000 PC 196.00000 PC 2̂Summary 26 PC 26 PC 340.00000 PC 2̂

Available in case of formulas with multiple structures, under “Formula Properties”.

Collisions always occur when point and dash calculations or functions are mixed in competing formulas.

If you do not make a definition, the formula that was set (defined and saved) last takes priority.

+

*

Page 39: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 39

Overview

KF/CKF Properties and Exception Aggregation OLAP Processor – Under the Hood Case Study “Revenue Calculation” Calculation with “Reference to Characteristic” Formula Collision Percentage and Summary Functions

Page 40: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 40

Percentage Functions (1)

a%b difference in percentage: How much does a value deviate from the absolute amount of b: = (a-)/abs(b)?

a%Ab share in percentage: How large is a share a for the total value b: = a/abs(b)

%CTa share in terms of percentage for the result: The value of the key figure a is related to the next higher value that is aggregated (the "subresult" of a with respect to a characteristic is 100%).

GTa share in terms of percentage for the total result: The value of the key figure a is related to the aggregated value for all characteristics (the

"result" of the entire table for the key figure a is 100%). %RTa share in terms of percentage for the report result:

The value of the key figure a is related to the aggregated value for all characteristics, for which the dynamic filter is ignored. If, for example, a free characteristic is restricted by a filter value, the global result of the key figure a in the displayed table is not 100%. The

aggregation via all filter values results in 100%.

Page 41: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 41

Percentage Functions (2)

KHMAT2

KHMAT2 Calendar year Quantity 'Quantity' % 10 'Quantity' %A 10 %CT 'Quantity' %GT 'Quantity' %RT 'Quantity'M1 2001 5.000 PC -50.00000 % 50.00000 % 45.45455 % 19.23077 % 19.23077 %

2002 6.000 PC -40.00000 % 60.00000 % 54.54545 % 23.07692 % 23.07692 %Result 11.000 PC 10.00000 % 110.00000 % 42.30769 % 42.30769 % 42.30769 %

M2 2001 7.000 PC -30.00000 % 70.00000 % 46.66667 % 26.92308 % 26.92308 %2002 8.000 PC -20.00000 % 80.00000 % 53.33333 % 30.76923 % 30.76923 %Result 15.000 PC 50.00000 % 150.00000 % 57.69231 % 57.69231 % 57.69231 %

Overall Result 26.000 PC 160.00000 % 260.00000 % 100.00000 % 100.00000 % 100.00000 %

KHMAT2 M1

Calendar year Quantity 'Quantity' % 10 'Quantity' %A 10 %CT 'Quantity' %GT 'Quantity' %RT 'Quantity'2001 5.000 PC -50.00000 % 50.00000 % 45.45455 % 45.45455 % 19.23077 %2002 6.000 PC -40.00000 % 60.00000 % 54.54545 % 54.54545 % 23.07692 %Overall Result 11.000 PC 10.00000 % 110.00000 % 100.00000 % 100.00000 % 42.30769 %

a%b difference in percentage a%Ab share in percentage %CTa share in terms of percentage for the result GTa share in terms of percentage for the total result %RTa share in terms of percentage for the report result

Page 42: KF After Before Aggregation

SAP AG 2002, Title of Presentation, Speaker Name 42

Summary Functions

KHMAT2

KHMAT2 Calendar year Quantity SUMCT 'Quantity' SUMGT 'Quantity' SUMRT 'Quantity'M1 2001 5.000 PC 11.000 PC 26.000 PC 26.000 PC

2002 6.000 PC 11.000 PC 26.000 PC 26.000 PCResult 11.000 PC 26.000 PC 26.000 PC 26.000 PC

M2 2001 7.000 PC 15.000 PC 26.000 PC 26.000 PC2002 8.000 PC 15.000 PC 26.000 PC 26.000 PCResult 15.000 PC 26.000 PC 26.000 PC 26.000 PC

Overall Result 26.000 PC 26.000 PC 26.000 PC 26.000 PC

KHMAT2 M1

Calendar year Quantity SUMCT 'Quantity' SUMGT 'Quantity' SUMRT 'Quantity'2001 5.000 PC 11.000 PC 11.000 PC 26.000 PC2002 6.000 PC 11.000 PC 11.000 PC 26.000 PCOverall Result 11.000 PC 11.000 PC 11.000 PC 26.000 PC

SUMGTa The value of the key figure a is related to the aggregate value via all characteristics. Aggregation is completed using the deepest-level characteristic.

SUMCTa

The value of the key figure a is related to the next highest aggregate value.

SUMRTa

The value of the key figure a is related to the aggregate value of all characteristics in which the dynamic filter is ignored.