You are on page 1of 50

Business Objects Designer Advanced Topics NC BOUG

Richard Foster August 29, 2002

Designers Dilemmas


Quick Hits

Chasm Fan Aggregate Awareness Linking Universes

Table Order Correlated Subqueries

Copyright 2000 Business Objects SA - All Rights Reserved

Tip 1: Table Order

Control the order of the tables in the FROM


clause

Default Sort from heavy to light tables

Number of rows in table For Oracle use REVERSE_TABLE_WEIGHT=Y in prm file (Default) REVERSE_TABLE_WEIGHT only valid for Oracle

Copyright 2000 Business Objects SA - All Rights Reserved

Tip 1: Table Order


Override number of rows in table setting
Right click on table Select Number of Rows in Table Use Modify manually tables row count as a weighting mechanism

Copyright 2000 Business Objects SA - All Rights Reserved

Tip 2: Correlated Subquery


Correlated Subquery that relates back to each row
returned by the primary query Create Predefined Condition

Conditions such as Maximum Date for each customer

Drag and drop condition in Query Panel


Much easier than Manually creating subqueries Teaching users how to create subqueries

Copyright 2000 Business Objects SA - All Rights Reserved

Tip 2: Correlated Subquery


Custom er Baker Baker Brendt Dupont Dupont Durnstein Edw ards Gentil Goldschmidt Hopkins Jones Jones Kamata Kamata Kamimura Kamimura Keegan Keegan Address 2890 Grant Avenue 2890 Grant Avenue 10 Jasper Blvd. 37 rue Murat 37 rue Murat Thomashof 22 68 Dow ning Street 17montee des Chenes 91 Torre drive The Gables 34 Apple Grove 34 Apple Grove 70 Kiroto Street 70 Kiroto Street 34 Kaw asaki Avenue 34 Kaw asaki Avenue 10 Hamilton Park 10 Hamilton Park Re servation Date 4/17/1996 4/8/1997 1/25/1996 5/21/1996 5/8/1997 5/22/1997 6/27/1996 4/23/1997 4/1/1997 5/23/1997 8/12/1996 9/10/1996 8/1/1996 9/8/1997 5/3/1996 6/15/1997 12/15/1996 8/4/1998
Custom er Baker Brendt Dupont Durnstein Edw ards Gentil Goldschmidt Hopkins Jones Kamata Kamimura Keegan Address 10 Jasper Blvd. 37 rue Murat Thomashof 22 Re servation Date 1/25/1996 5/8/1997 5/22/1997 2890 Grant A venue 4/8/1997

68 Dow ning Street6/27/1996 17montee des Chenes 4/23/1997 91 Torre drive The Gables 34 Apple Grove 70 Kiroto Street 10 Hamilton Park 4/1/1997 5/23/1997 9/10/1996 9/8/1997 8/4/1998

34 Kaw asaki Avenue 6/15/1997

Copyright 2000 Business Objects SA - All Rights Reserved

Tip 2: Correlated Subquery

Copyright 2000 Business Objects SA - All Rights Reserved

Tip 2: Correlated Subquery


SELECT Customer.last_name,

Customer.address,
Reservations.res_date FROM Customer, Reservations

WHERE
( Customer.cust_id=Reservations.cust_id ) AND ( ( Reservations.res_date=ANY(SELECT max(T1.res_date) from Reservations T1 WHERE T1.cust_id = Reservations.cust_id) ) )

Copyright 2000 Business Objects SA - All Rights Reserved

Tip 2: Correlated Subquery


The

BusinessObjects parser will not see the Customer table hidden within the SELECT unless other objects from the Customer table are included in the query To ensure this manually add the table to the list of implicated tables
Click

the Table button Select additional tables


Copyright 2000 Business Objects SA - All Rights Reserved

Tip 3: Chasm Trap

Chasm trap is a limitation of SQL The Chasm trap occurs when two many-to
one joins converge on a single table. Results in a partial Cartesian product

Copyright 2000 Business Objects SA - All Rights Reserved

10

Tip 3: Chasm Trap

Incorrect results are possible when:


A "many to one to many relationship" exists among three
tables in the universe structure The query includes objects based on two tables both at the "many" end of their respective joins There are multiple rows returned for a single dimension

Copyright 2000 Business Objects SA - All Rights Reserved

11

Example Data(Chasm Trap)


Cust Id Order Id Order Date Order V alue 10 10 10 28 28 18109 1/12/1999 20072 4/14/1999 20828 9/20/1999 18598 1/31/1999 20133 6/4/1999 10,000 15,000 18,000 12,000 4,000

Cust Id

Cust Name 10 Paul 19 Mary 28 Cathy

Cust Id Loan Id Loan Date 10 10 19 19 190 8/5/1998 397 6/3/1999 236 12/13/1998 459 7/19/1999

Loan Amount 5,000 10,000 7,000 2,000

Copyright 2000 Business Objects SA - All Rights Reserved

12

Detail results
Cust Name Paul
Cust Nam e Paul Paul Paul Paul Paul Paul

Loan Amount 45,000

Order Value 86,000


Order Date Order V alue 1/12/1999 4/14/1999 9/20/1999 1/12/1999 4/14/1999 9/20/1999 10,000 15,000 18,000 10,000 15,000 18,000

SELECT Customer.cust_name,

Loan Date Loan Am ount 8/5/1998 8/5/1998 8/5/1998 6/3/1999 6/3/1999 6/3/1999 5,000 5,000 5,000 10,000 10,000 10,000

Loans.loan_date, sum(Loans.loan_amount), Orders.order_date, sum(Orders.order_value) FROM Customer, Loans,

Pauls

totals incorrect
should be 15,000 should be 43,000

Orders
WHERE

Loans

( Customer.cust_id=Loans.cust_id ) AND ( Customer.cust_id=Orders.cust_id ) GROUP BY Customer.cust_name, Loans.loan_date, Orders.order_date

Orders

Pauls Mary

loans and orders displayed too many times

and Cathy missing from report

Copyright 2000 Business Objects SA - All Rights Reserved

13

Tip 3: Chasm

Select the option Multiple SQL Statements for Each Measure from the Universe Parameters dialog box.

Only applies to measures. You force the SQL generation engine in Reporter to generate SQL queries for each measure that appears in the Query panel. You cannot use this solution to generate multiple SQL statements for dimensions. Option is on by default.

Copyright 2000 Business Objects SA - All Rights Reserved

14

Detail results With Multiple SQL Statements


SELECT Customer.cust_name, Loans.loan_date, Orders.order_date, sum(Loans.loan_amount) FROM Customer, Loans, Orders WHERE
Cust Name Cathy Mary Paul 9,000 15,000 43,000

Two
Paul Paul Paul Paul Paul Paul

SELECT statements generated


8/5/1998 8/5/1998 8/5/1998 6/3/1999 6/3/1999 6/3/1999 1/12/1999 4/14/1999 9/20/1999 1/12/1999 4/14/1999 9/20/1999 Sum : 5,000 5,000 5,000 10,000 10,000 10,000 45,000 10,000 15,000 18,000 10,000 15,000 18,000 86,000

SELECT Customer.cust_name, Loans.loan_date, Orders.order_date, sum(Orders.order_value) FROM Customer, Loans, Orders WHERE

Cust Nam e Loan Date Order Date Loan Am ount Order V alue

Loan Amount

Order Value 16,000

( Customer.cust_id=Loans.cust_id )
AND ( Customer.cust_id=Orders.cust_id ) GROUP BY Customer.cust_name, Loans.loan_date, Orders.order_date

( Customer.cust_id=Loans.cust_id )
AND ( Customer.cust_id=Orders.cust_id ) GROUP BY Customer.cust_name,

Customer

totals report correct

Loans.loan_date, Orders.order_date

Mary

and Cathy missing from detail report


detail incorrect

Pauls

Copyright 2000 Business Objects SA - All Rights Reserved

15

Tip 3: Chasm

Define a context for each table at the "many" end of the joins.

In our example you could define a context from CUSTOMER to ORDERS and from CUSTOMER to LOANS. This creates two SQL statements and two separate tables in Business Objects, avoiding the creation of a Cartesian product. Using contexts is the most effective way to solve Chasm traps.

Copyright 2000 Business Objects SA - All Rights Reserved

16

Tip 3: Chasm

Define a context for each table at the "many" end of the joins.

Multiple SQL statements for each context must be selected. It is checked by default. If not you will receive the Incompatible Objects error message.

Copyright 2000 Business Objects SA - All Rights Reserved

17

Detail Results Correct Using Contexts


Cathy
Loan Date
Sum:

Loan Amount

Order Date
1/31/1999 6/4/1999 Sum:

Order Value
12,000 4,000 16,000

SELECT Customer.cust_name, Orders.order_date,

SELECT Customer.cust_name, Loans.loan_date, sum(Loans.loan_amount) FROM Customer, Loans

Mary
Loan Date
12/13/1998 7/19/1999 Sum:

sum(Orders.order_value) FROM

Loan Am ount
7,000 2,000 9,000

Order Date
Sum:

Order Value

Customer, Orders

WHERE
( Customer.cust_id=Orders.cust_id ) GROUP BY Customer.cust_name,

WHERE
( Customer.cust_id=Loans.cust_id ) GROUP BY Customer.cust_name, Loans.loan_date

Paul
Loan Date
8/5/1998 6/3/1999 Sum:

Orders.order_date

Loan Am ount
5,000 10,000 15,000

Order Date
1/12/1999 4/14/1999 9/20/1999 Sum:

Order Value
10,000 15,000 18,000 43,000

Copyright 2000 Business Objects SA - All Rights Reserved

18

Tip 4: Fan Trap


The Fan Trap occurs when a "one to many" join links a table
which is in turn linked by another "one to many" join. The fanning out effect of "one to many" joins can cause incorrect results to be returned when a query includes objects based on both tables Incorrect results are possible when: An aggregate function is performed on the table at the "one" end of the

join, while still joining to the "many" end For example, a query is run that asks for the total orders by each order line, for a particular customer

Copyright 2000 Business Objects SA - All Rights Reserved

19

Example Data(Fan Trap)

Order Id Product Quantity Sold Value


Cust Id Customer Name 321 Dav e 322 Paul 323 Pete
Cust Id Order Id Total Value 322 323 12345 554433 550,000 23,000

12345 BMW 12345 Kia 12345 Rolls 554433 Kia

3 1 5 3

160,000 10,000 380,000 30,000

Copyright 2000 Business Objects SA - All Rights Reserved

20

Totals and Detail results


Custom er Nam e Product Total V alue Quantity Sold

Both reports, summary and detail, are incorrect


Cust Name Paul Pete Total Value 1,650,000 23,000 Quantity Sold 9 3

Paul

BMW Kia Rolls

550,000 550,000 550,000 1,650,000

3 1 5 9

Paul

Sum :

Custom er Nam e Product Total V alue Quantity Sold Pete Pe te Kia Sum : 23,000 23,000 3 3

SELECT Customer.cust_name, sum(Orders.total_value), sum(Order_Lines.qty_sold) FROM Customer, Orders, Order_Lines WHERE ( Customer.cust_id=Orders.cust_id ) AND ( Orders.order_id=Order_Lines.order_id )

SELECT Customer.cust_name, sum(Orders.total_value),

sum(Order_Lines.qty_sold), Order_Lines.prod_id
FROM Customer, Orders, Order_Lines WHERE ( Customer.cust_id=Orders.cust_id ) AND ( Orders.order_id=Order_Lines.order_id ) GROUP BY Customer.cust_name, Order_Lines.prod_id

GROUP BY
Customer.cust_name

Copyright 2000 Business Objects SA - All Rights Reserved

21

Results

Total Order Value per customer as well as the Quantity sold

Expected answer:
Paul Pete $ 550,000 9 Cars $ 23,000 3 Cars $1,650,000 9 Cars $ 23,000 3 Cars

Values returned when run in ONE SQL statement


Paul Pete

Copyright 2000 Business Objects SA - All Rights Reserved

22

Fan Trap Resolution 1

Multiple SQL statements for each measure


As the measure objects are based of different tables this resolves the problem. BusinessObjects runs two queries and combines the results. (This setting is on by default.)

Copyright 2000 Business Objects SA - All Rights Reserved

23

Results With Multiple SQL Statements


Totals Summary
Cust Name Paul Pete Total Value 550,000 23,000 Quantity Sold 9 3

SELECT Customer.cust_name, sum(Orders.total_value) FROM

SELECT Customer.cust_name, sum(Order_Lines.qty_sold) FROM Customer, Order_Lines, Orders WHERE ( Customer.cust_id=Orders.cust_id ) AND ( (Orders.order_id=Order_Lines.order_id ) GROUP BY Customer.cust_name

Customer, Orders
WHERE ( Customer.cust_id=Orders.cust_id ) GROUP BY Customer.cust_name

Results

are correct

But..

Copyright 2000 Business Objects SA - All Rights Reserved

24

Results With Multiple SQL Statements


Detail Report
Cust Nam e Paul Prod Id BMW Kia Rolls Paul Sum : Prod Id Kia Sum : Total Value 550,000 550,000 550,000 1,650,000 Quantity Sold 3 1 5

SELECT Customer.cust_name, Order_Lines.prod_id, sum(Orders.total_value) FROM Customer, Order_Lines, Orders WHERE ( Customer.cust_id=Orders.cust_id ) AND ( Orders.order_id=Order_Lines.order_id ) GROUP BY Customer.cust_name, Order_Lines.prod_id
Cust Nam e Pete Pe te Total Value 23,000 23,000 Quantity Sold 3

SELECT Customer.cust_name, Order_Lines.prod_id, sum(Order_Lines.qty_sold) FROM Customer, Order_Lines, Orders WHERE ( Customer.cust_id=Orders.cust_id ) AND ( Orders.order_id=Order_Lines.order_id ) GROUP BY

Customer.cust_name,

Detail

results are still incorrect

Order_Lines.prod_id

Copyright 2000 Business Objects SA - All Rights Reserved

25

Fan Trap Resolution 1


When does this NOT resolve the problem?

Adding Dimensions or details from the Many side of the relationship will cause inflated results.

In our example, the Prod Id is the added dimension from the many side

Copyright 2000 Business Objects SA - All Rights Reserved

26

Fan Trap Resolution Part 2

Alias and Context


1. Create an Alias for the Orders table, modify the measure object to use the Alias of the Orders table (sum(Orders2.Total_Value) ). 2. Detect Contexts. 3. Ensure Multiple SQL statements for each context is selected 4. BusinessObjects will run two queries. One to return the detail line information and one for the total. 5. Two blocks of data will be displayed.

Copyright 2000 Business Objects SA - All Rights Reserved

27

Detail Results Correct


Paul
Total Value 550,000
Prod Id BMW Kia Rolls Quantity Sold 3 1 5

Two

select statements produced

Context
Correct

used
results
SELECT Customer.cust_name, Order_Lines.prod_id, sum(Order_Lines.qty_sold) FROM Customer, Order_Lines, Orders WHERE ( Customer.cust_id=Orders.cust_id ) AND ( Orders.order_id=Order_Lines.order_id )

Pete
Total Value 23,000 Prod Id Kia Quantity Sold 3

SELECT Customer.cust_name, sum(Orders2.total_value) FROM Customer, Orders Orders2, Orders WHERE ( Customer.cust_id=Orders.cust_id ) AND ( Orders.cust_id=Orders2.cust_id and Orders.order_id=Orders2.order_id ) GROUP BY Customer.cust_name

GROUP BY
Customer.cust_name, Order_Lines.prod_id

Copyright 2000 Business Objects SA - All Rights Reserved

28

Tip 4: Aggregate Awareness

Copyright 2000 Business Objects SA - All Rights Reserved

29

Tip 4: Aggregate Awareness

Copyright 2000 Business Objects SA - All Rights Reserved

30

Tip 4: Aggregate Awareness

Copyright 2000 Business Objects SA - All Rights Reserved

31

Tip 4: Aggregate Awareness


@Aggregate_Aware (sum(Agg_yr_qt_rn_st_ln_ca_sr.Sales_revenue), sum(Agg_yr_qt_mt_mn_wk_rg_cy_sn_sr_qt_ma.Sales_revenue), sum(Shop_facts.Amount_sold))

For the Sales Revenue object, attempt to get the Sales Revenue figure from the year_quarter_agg_table table first, if that cant be done then try the year_quarter_month_week_agg_table next. And so on. The decision as to whether a particular table is chosen is made by reference to the Aggregate Navigation rules which are setup separately.

Copyright 2000 Business Objects SA - All Rights Reserved

32

Aggregate Analysis Procedure


Step 1: Create summary tables Step 2: Define @AggregateAware objects Step 3: Define incompatibilities Step 4: Consolidate dimensions Step 5: Define contexts to separate levels of aggregation

Copyright 2000 Business Objects SA - All Rights Reserved

33

Step 1: Creating Summary Tables

eFashion contains the following summary tables

Copyright 2000 Business Objects SA - All Rights Reserved

34

Step 2: Define @AggregateAware Objects

The formula for Sales Revenue might be


@Aggregate_Aware( sum(Agg_yr_qt_mt_mn_wk_rg_cy_sn_sr_qt_ma.Sales_revenue), sum(Agg_yr_qt_rn_st_ln_ca_sr.Sales_revenue), sum(Shop_facts.Amount_sold))

Speed
Notice how the expressions are arranged, with the most summarized or fastest calculations on top

Copyright 2000 Business Objects SA - All Rights Reserved

35

Step 3: Define Incompatibilities

In Designer, identify which summary tables and objects cannot be used in the same query

Select Tools / Aggregate Navigation from the Designer menu


Copyright 2000 Business Objects SA - All Rights Reserved

36

Step 3: Define Incompatibilities

Warning: Detect Incompatibility is not 100%


Multiple fact tables will be considered incompatible with each other because the auto detection uses contexts to determine incompatibility.Multiple fact tables are usually on separate contexts. Aggregate aware dimension objects will not be considered incompatible with dimension tables at a lower level than themselves (the object comes from a table on the same context as the lower level tables).

Copyright 2000 Business Objects SA - All Rights Reserved

37

Step 3: Define Incompatibilities


If

class shows an empty checkbox, individual dimensions in that class may be selected, ie. Store\State
If

a class is selected, all objects in that class are also selected, ie. Product
This

aggregate table contains Year, Quarter, Month, Week but not Holiday. So Holiday is incompatible.
The

aggregate table contains City and Store Name but not State or any of the Store Details. So State and all the Store Details are incompatible.

Copyright 2000 Business Objects SA - All Rights Reserved

38

Step 3: Define Incompatibilities


This

aggregate table contains only Year and Quarter. So the remaining Time objects are incompatible.
The

aggregate table contains just State from the Store class. So the remaining Store objects are incompatible.

Copyright 2000 Business Objects SA - All Rights Reserved

39

Step 4: Consolidate Dimensions


Year is stored in the summary tables as well as the Calendar dimension Based on number of rows, the summary tables would retrieve values faster Objects other than measures can be consolidated using aggregate aware techniques
@Aggregate_Aware( Agg_yr_qt_mt_mn_wk_rg_cy_sn_sr_qt_ma.Year, Agg_yr_qt_rn_st_ln_ca_sr.Year, Calendar_year_lookup.Year)

Copyright 2000 Business Objects SA - All Rights Reserved

40

Step 5: Define Contexts


The summary tables presented so far were isolated not joined to any other table Many summarized tables can be joined by keeping one or more foreign keys from the original fact table The Annual_Shop_facts table summarizes revenue by year, product, and store

Copyright 2000 Business Objects SA - All Rights Reserved

41

Step 5: Define Contexts (continued)

The eFashion database with this new summary table

Copyright 2000 Business Objects SA - All Rights Reserved

42

Step 5: Define Contexts (continued)

The extra summary table has introduced a loop

Annual_Shop_facts to Article_lookup to Shop_facts to Outlet_lookup to Annual_Shop_facts

Loops within the universe will prevent queries from running Contexts can be used to separate the levels of aggregation, and break the loop

Copyright 2000 Business Objects SA - All Rights Reserved

43

Step 5: Define Contexts (continued)


The Annual Shop Facts context

and the Shop Facts context

Copyright 2000 Business Objects SA - All Rights Reserved

44

Tip 5: Linking Universes

Rules & Limitations


Each universe connection must point to same database Only one level of linking allowed No duplicate class names All related universes in same universe domain Care must be used in migrating from one universe domain to another such as Development to Production Contexts and Hierarchies will not carry over to linked universes If being used, Table Weights must be applied to all universes involved Use CORE_ORDER_PRIORITY=Y in prm for automatic modification of an objects status in a derived universe from the core Do not mix approaches

Copyright 2000 Business Objects SA - All Rights Reserved

45

Tip 5: Linking Universes

Three approaches

Kernel contains core common elements Master contains all elements Component merging universes Insert menu, select Universe to bring in the kernel universe Edit menu, select Links to alter linked universes

General Designer Navigation


Include will bring in kernel as part of the universe, destroying the link Change Source normally used in universe migration Remove Link does exactly that

Kernel universes and their associated classes\objects will always appeared grayed out

Copyright 2000 Business Objects SA - All Rights Reserved

46

Tip 5: Linking Universes


Kernel HR Sales Kernel

Kernel approach

Kernel

Kernel contains core common elements Add specific components Kernel of the linked universes automatically updated Bring in kernel universe Use table browser to add new tables Join new tables into kernel Add new classes\objects from new tables Add new class\objects from kernel

Designer

Kernel

Only one level of linking allowed

Copyright 2000 Business Objects SA - All Rights Reserved

47

Tip 5: Linking Universes


Master HR Master Sales

Master approach

Master

Master contains all Hide unnecessary objects Only one universe to maintain

Designer

Bring in kernel universe From the Insert menu select Universe As in normal universe, right click on an object or class and select Hide

Copyright 2000 Business Objects SA - All Rights Reserved

48

Tip 5: Linking Universes


Part 1 Part 2 Sales Part 1 Part 2

Component approach

Merging two or more universes into one View several subuniverses as a whole

Designer

Insert multiple universes Universes must be joined by at least two tables Create new classes\objects

Copyright 2000 Business Objects SA - All Rights Reserved

49

End of presentation

Copyright 2000 Business Objects SA - All Rights Reserved

50

You might also like