48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

15
WebIntelligence version 6 Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects Overview The ability to define complex formulas in either WebIntelligence or BusinessObjects reports is one of the very powerful features of these products. This document provides additional explanation on how to do this, including many examples. This document should be read by advanced report creators who have already mastered the basics of report writing. Contents INTRODUCTION ............................................................................................ 3 WHAT ARE CALCULATION CONTEXTS............................................................ 3 HOW TO CHECK RESULTS ............................................................................ 3 The Input Context and the Measure ............................................................. 4 Filters ................................................................................................................. 4 Simplification of the Output context .................................................................. 4 Output context ................................................................................................... 4 Application of the Aggregation function ........................................................... 5 Report this variable in your report ..................................................................... 6 #MULTIVALUE ............................................................................................ 6 CONTEXT OPERATORS (IN, FOREACH, FORALL) ........................................... 6 EXTENDED SYNTAX KEYWORDS.................................................................... 7 In Report ...................................................................................................... 7 In Section ..................................................................................................... 7 In Block ........................................................................................................ 8 In Break ....................................................................................................... 8 In Body ......................................................................................................... 9 DEFAULT CALCULATION CONTEXTS .............................................................. 9 Vertical and Horizontal tables ..................................................................... 9 Cross Tables .............................................................................................. 10 Section........................................................................................................ 11 Break .......................................................................................................... 12 MEASURE WITHOUT EXPLICIT AGGREGATION FUNCTION .............................. 13 =<REVENUE> IN (<COUNTRY>) ................................................................. 13 10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 1

Transcript of 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

Page 1: 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

WebIntelligence version 6

Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects

Overview The ability to define complex formulas in either WebIntelligence or BusinessObjects reports is one of the very powerful features of these products. This document provides additional explanation on how to do this, including many examples.

This document should be read by advanced report creators who have already mastered the basics of report writing.

Contents INTRODUCTION............................................................................................3 WHAT ARE CALCULATION CONTEXTS............................................................3 HOW TO CHECK RESULTS ............................................................................3

The Input Context and the Measure.............................................................4 Filters................................................................................................................. 4 Simplification of the Output context.................................................................. 4 Output context ................................................................................................... 4 Application of the Aggregation function ........................................................... 5 Report this variable in your report ..................................................................... 6

#MULTIVALUE ............................................................................................6 CONTEXT OPERATORS (IN, FOREACH, FORALL)...........................................6 EXTENDED SYNTAX KEYWORDS....................................................................7

In Report ......................................................................................................7 In Section .....................................................................................................7 In Block........................................................................................................8 In Break .......................................................................................................8 In Body.........................................................................................................9

DEFAULT CALCULATION CONTEXTS..............................................................9 Vertical and Horizontal tables.....................................................................9 Cross Tables ..............................................................................................10 Section........................................................................................................11 Break..........................................................................................................12

MEASURE WITHOUT EXPLICIT AGGREGATION FUNCTION ..............................13 =<REVENUE> IN (<COUNTRY>) .................................................................13

10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 1

Page 2: 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

WebIntelligence version 6 Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects

FINDING MORE INFORMATION ....................................................................15

10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 2

Page 3: 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

WebIntelligence version 6 Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects

Introduction Before you can define a specific calculation context, you must first understand how calculation contexts work.

What are calculation contexts Calculation contexts give you more control over how a formula or measure is evaluated. To understand them, you must be familiar with basic report concepts.

A report contains two kinds of objects:

• Dimensions - Types of data about your business that can have measures associated with them (for example: products, years, and states)

• Measures - You can calculate them in relation to dimensions (for example: <Sales revenue> and <Number of sales>). For example, a report could show <Sales revenue> (measure) by <Year> (dimension).

The important thing to remember about measures is that they are semantically dynamic. This means that the figures returned by a measure depend on the dimensions with which it is associated; in other words, on the context in which it is placed.

WebIntelligence/BusinessObjects (from now on we will only refer to WebIntelligence) places each measure in its default context depending on where they appear in the report. However, you can change this default context. This is what is meant by defining the calculation context.

You can see default contexts by creating a block containing <Year> and <Sales Revenue> objects. In this case, the <Sales Revenue> object returns the revenue by year, because the revenue is evaluated in the context of the <Year> dimension. If you then add the <Quarter> dimension to the block, then the figures in the <Sales Revenue> column change because the default context is now <Year> and <Quarter>. From this you can see that when you place a measure or formula in a block, the default calculation context that WebIntelligence applies includes all the dimensions in the block.

How to check results Each measure is evaluated by an input and output context. With an explicit expression, the general syntax is:

Aggregate_function (Measure_Object In (Input_Context) ) In (Output_Context)

Where:

• Aggregate_function: Sum, Max, Min, Count, Average, Median, etc.

• Measure_Object: a formula or a variable; e.g., <Revenue>

• Input_Context and Output_Context: dimension(s) to evaluate the measure

10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 3

Page 4: 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

WebIntelligence version 6 Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects

Here is an example on how to evaluate the following formula:

=Max(<Revenue> In (<Country> ,<Year>) ) In (<Country >, <Resort>)

• Aggregate_function: Max

• Measure_Object: <Revenue>

• Input_Context: (<Country>, <Year>)

• Output_Context: (<Country >, <Resort>)

The Input Context and the Measure We evaluate the measure in the input context. It means that we create a vertical table with input context dimension(s) and the measure objects selected.

Country Year RevenueFrance FY00 259,170.00France FY98 295,940.00France FY99 280,310.00US FY00 856,560.00US FY98 767,614.00US FY99 826,930.00

Filters A global filter or report filter should be applied.

If your formula is in a block, then you should also apply block filters, except if you use “In Section” in your input context definition.

Simplification of the Output context In the output context, we remove all dimensions that are not in the input context. For example, if we have the following defined:

• Input_Context: (<Country> ,<Year>)

• Output_Context: (<Country>, <Resort >)

Then the Output_Context becomes only (<Country>).

Output context On the previous block, we will create a break, based on the output context dimensions.

If the output context is In Report or with no dimension, then breaks are not necessary.

10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 4

Page 5: 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

WebIntelligence version 6 Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects

Country Year RevenueFrance FY00 259,170.00

FY98 295,940.00FY99 280,310.00

France

Country Year RevenueUS FY00 856,560.00

FY98 767,614.00FY99 826,930.00

US

Application of the Aggregation function We can apply the aggregation function on the measure, Max(Revenue) in the example below:

Country Year RevenueFrance FY00 259,170.00

FY98 295,940.00FY99 280,310.00

France Maximum: 295,940.00

Country Year RevenueUS FY00 856,560.00

FY98 767,614.00FY99 826,930.00

US Maximum: 856,560.00

Only one value is returned for each group of dimensions; in our case, one Max(Revenue) value by <Country>.

If the output context is In Report or with no dimension, then you obtain only one value in the table footer. The value is: 856,560.00.

=Max(<Revenue> in (<Country> ,<Year>) ) in Report

Country

Year RevenueFrance FY00 259,170.00France FY98 295,940.00France

FY99 280,310.00US FY00 856,560.00US

FY98 767,614.00US FY99 826,930.00

Maximum: 856,560.00

10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 5

Page 6: 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

WebIntelligence version 6 Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects

Report this variable in your report For each group of values Country-Resort, one result is returned (see the last column):

Country Resort RevenueMax(<Revenue> In(<Country> ,<Year>) ) In(<Country>, <Resort>)

France French Riviera 835,420.00 295,940.00US Bahamas Beach 971,444.00 856,560.00US Hawaiian Club 1,479,660.00 856,560.00

#MultiValue Sometimes, instead of getting the correct value in a formula, a #MultiValue result is returned. This can happen if the application cannot calculate the formula for a corresponding group of values.

In the previous example, if you would put the formula in the table header, then you obtain #MultiValue:

Country Resort Revenue #MULTIVALUEFrance French Riviera 295,940.00 295,940.00US Bahamas Beach 856,560.00 856,560.00US Hawaiian Club 856,560.00 856,560.00

This happens because there are two possible values to calculate Max(Revenue) for: one for US and one for France. The system does not know which one to use.

Context operators (In, ForEach, ForAll) In the examples so far, we specified input and output contexts by using the reserved word “In”, then listing dimensions to be included in the context. “In” is known as context operator. The other context operators are “ForEach” and “ForAll”.

The following table describes the three context operators:

In Used to specify dimensions explicitly. Also used with extended syntax keywords.

ForEach Adds dimensions to the context.

ForAll Removes dimensions from the context.

ForAll and ForEach are used to modify a context by adding or removing dimension(s). This has been designed to modify the default context. The context operators can be used as input or output context.

10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 6

Page 7: 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

WebIntelligence version 6 Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects

We can transform a formula to evaluate a ForEach clause to an In clause as in the following examples:

is equivalent to: In (<Country>,<Resort>,<Year>) ForAll (<Country>) In (<Resort>,<Year>) In (<Country>,<Resort>,<Year>) ForEach (<Quarter>) In (<Country>,<Resort>,<Year>, <Quarter>)

In (<Country>,<Resort>,<Year>) ForAll (<Country>, <Service>)

In (<Resort>,<Year>)

In (<Country>,<Resort>,<Year>) ForEach (<Country>,<Quarter>)

In (<Country>,<Resort>,<Year>, <Quarter>)

Extended syntax keywords Extended syntax keywords are a form of “shorthand” that allows you to refer to dimensions in extended syntax without specifying those dimensions explicitly.

This helps future-proof reports; if formulas do not contain hard-coded references to dimensions, then they will continue to work even if dimensions are added to or removed from a report.

There are five extended syntax keywords: Report, Section, Break, Block, and Body

In Report “In Report” means “All data in the report”.

<Revenue> In Report

This means that we evaluate the measure without dimension. We create a report with only a cell containing “=<Revenue>”.

The equivalent is: In () - with no dimension(s). For example:

is equivalent to:

In Report ForEach (<Resort>,<Year>) In (<Resort>,<Year>)

In (<Resort>,<Year>) ForAll (<Resort>,<Year>) In Report

In Section We work with the value of a Section. The equivalent is:

In (CurrentSection + Upper Section Dimensions)

If not “In Section”, then it equals “In Report”.

10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 7

Page 8: 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

WebIntelligence version 6 Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects

It is similar to “In Block”, but Ignore Block Filter

For example, if we have two sections on <Year> and <Quarter>:

is equivalent to:

In Section (in section Year) In (<Year>)

In Section (in section Quarter) In (<Year>, <Quarter>)

In Section ForEach (<Resort>)

(in section Year)

In (<Year>, <Resort>)

In Block We work with the value of a Block. The equivalent is:

ForAll (All Block Dimension)

It is similar as “In Section”, but Respect Block Filter

For example, if we have a block containing <Country>, <Resort>, and a section on <Year>:

is equivalent to:

In Block In (<Country>, <Resort>,<Year>) ForAll (<Country>, <Resort>)

Equals:

In (<Year>)

In Block ForEach (<Resort>) In (<Year>, <Resort>)

In Break You use it inside a break and the equivalent is:

In (All Break Dimensions + Section Dimension)

For example, if we have a block with <Year>, <Quarter>, <Service>, and breaks on <Year> and <Quarter>, and a section on <Country>:

is equivalent to:

In Break In (<Country>, <Quarter>,<Year>)

10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 8

Page 9: 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

WebIntelligence version 6 Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects

In Body “In Body” is the default input context.

When placed in... References this data...

A block (body, header, or footer) Dimensions in the block (In (All Block Dimensions) )

A block break (header or footer) Dimensions in the block (In (All Block Dimensions) )

A section (header, footer, or outside a block) Dimensions in the section (In Section ?????)

Outside any blocks or sections Section Dimensions in the report (All Sections Dimension)

Default calculation contexts

Vertical and Horizontal tables We study a table (<Resort>, <Year>, <Revenue>, and Max(Revenue) ) in a <Country> section:

When your calculation is

Input Context Output Context

Header or Footer

The dimensions used to generate the body of the block (All block dimensions + Section dimensions) E.g.: In (<Resort>, <Year>, <Country>)

All Section dimensions, if no section then “in Report” E.g.: In (<Country>)

Body

The dimensions used to generate the body of the block (All block dimensions + Section dimensions) E.g.: In (<Resort>, <Year>, <Country>)

Same as Input Context The dimensions used to generate the body of the block (All block dimensions + Section dimensions) E.g.: In (<Resort>, <Year>, <Country>)

10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 9

Page 10: 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

WebIntelligence version 6 Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects

Cross Tables We study a cross table (Columns: Year, Quarter, Rows: Resort, Body: Revenue) in a <Country> section.

10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 10

Page 11: 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

WebIntelligence version 6 Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects

When your calculation is …

Input Context Output Context

Body The dimensions used to generate the block (All block dimensions + section dimensions) E.g.: In (<Resort>, <Year>, <Quarter>, <Country>)

Same as Input Context The dimensions used to generate the body of the block (All block dimensions + section dimensions) E.g.: In (<Resort>, <Year>, <Quarter>, <Country>)

VBody Header or VBody Footer

The dimensions used to generate the block (All block dimensions + section dimensions) E.g.: In (<Resort>, <Year>, <Quarter>, <Country>)

The dimensions used to generate the rows of the block (All rows dimensions + section dimensions) E.g.: In (<Resort>, <Country>)

HBody Header or HBody Footer

The dimensions used to generate the block (All block dimensions + section dimensions) E.g.: In (<Resort>, <Year>, <Quarter>, <Country>)

The dimensions used to generate the columns of the block (All Column dimensions + section dimensions) E.g.: In (<Year>, <Quarter>, <Country>)

Header or Footer or VFooter or HFooter

The dimensions used to generate the block (All block dimensions + section dimensions) E.g.: In (<Resort>, <Year>, <Quarter>, <Country>)

All Section dimensions, if no section then “in Report” E.g.: In (<Country>)

Section A section may have: Header, Footer, and Body. We will study a free cell Max(Revenue) with the <Country> and <Year> sections:

10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 11

Page 12: 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

WebIntelligence version 6 Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects

When your calculation is …

Input Context Output Context

Body / Header / Footer

The dimensions used to generate all sections (All section dimensions) E.g.: In (<Year>, <Country>)

Current section dimension + previous ones E.g.: • Section Year: In (<Year>,

<Country>) • Section Country: In (<Country>) • Main section : In Report

Break We study a table (Resort, Year, Quarter, Revenue, Max(Revenue) ) with two breaks on Year then Quarter and a <Country> section.

When your calculation is …

Input Context Output Context

Break Header or Break Footer

The dimensions used to generate the body of the block (All block dimensions + section dimensions) E.g.: In (<Resort>, <Year>, <Quarter>, <Country>)

All section dimensions + current breaks dimension + previous break dimension E.g.: • Break Quarter: In (<Country>, <Year>,

<Quarter>) • Break Year: In (<Country>, <Year>)

10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 12

Page 13: 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

WebIntelligence version 6 Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects

Break Body Equal Table Body The dimensions used to generate the body of the block (All block dimensions + section dimensions) E.g.: In (<Resort>, <Year>, <Quarter>, <Country>)

Same as Input Context The dimensions used to generate the body of the block (All block dimensions + section dimensions) E.g.: In (<Resort>, <Year>, <Quarter>, <Country>)

Measure without explicit aggregation function =<Revenue> in (<Country>)

The issue is how to evaluate a measure (generally a variable that comes from a data provider or the variable editor).

A measure may have a default aggregation function. For a measure that comes from a data provider, the aggregation function is set in the universe as a property of the measure object. The different aggregation functions are: Sum, Max, Min, Average, Count, and None.

10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 13

Page 14: 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

WebIntelligence version 6 Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects

In BusinessObjects, you can see it in the DataManager:

For a document variable, generally, it’s SUM also.

When your calculation is … Extended syntax General Syntax

=<My Measure> =<My Measure> in OutPutContext

= Agg_function(<My Measure> in Body) in Body = Agg_function(<My Measure> in Body) in OutPutContext

=<Revenue> =Sum(<Revenue> in Body )

=<Revenue> in (<Country>) =Sum(<Revenue> in Body ) in (<Country>)

10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 14

Page 15: 48840875 Output Input Contexts in Formulas for Web Intelligence and Business Objects

WebIntelligence version 6 Output/Input Contexts in Formulas for WebIntelligence and BusinessObjects

Finding More Information For more information and resources, refer to the product documentation and visit the support area of the web site at: www.businessobjects.com

1. BusinessObjects Advanced Query Building Techniques Guide (businessobjects_advanced.pdf), Chapter 1, “Understanding Calculation Contexts“

2. WebIntelligence User’s Guide, Chapter 21, “Creating Custom Calculations”, “Defining the Calculation context”, and “Creating Custom calculation”

3. BusinessObjects User’s Guide: Accessing Data and Data Analysis, Chapter 15, “Calculation Contexts and Extended Syntax”

www.businessobjects.com

Business Objects owns the following U.S. patents, which may cover products that are offered and sold by Business Objects: 5,555,403, 6,247,008 B1, 6,578,027 B2, 6,490,593 and 6,289,352. Business Objects, the Business Objects logo, Crystal Reports, and Crystal Enterprise are trademarks or registered trademarks of Business Objects SA or its affiliated companies in the United States and other countries. All other names mentioned herein may be trademarks of their respective owners. Product specifications and program conditions are subject to change without notice. Copyright © 2004 Business Objects. All rights reserved.

10/1/2004 12:39 PM Copyright © 2004 Business Objects. All rights reserved. Page 15