Business Objects Designer Advanced Topics NC Boug: Richard Foster August 29, 2002

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 51

Business Objects Designer

Advanced Topics
NC BOUG
Richard Foster
August 29, 2002
Designer’s Dilemmas

• Quick Hits
• Table Order
• Correlated Subqueries
• Chasm
• Fan
• Aggregate Awareness
• Linking Universes

Copyright © 2000 Business Objects SA - All Rights Reserved


2
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


3
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


4
Tip 2: Correlated Subquery

• “Correlated”  Subquery that relates back to each row


returned by the primary query
• Conditions such as “Maximum Date” for each customer
• Create Predefined Condition
• 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


5
Tip 2: Correlated Subquery
Customer Address Reservation Date Customer Address Reservation Date
Baker 2890 Grant Avenue 4/17/1996 Baker 2890 Grant Avenue4/8/1997
Baker 2890 Grant Avenue 4/8/1997 Brendt 10 Jasper Blvd. 1/25/1996
Brendt 10 Jasper Blvd. 1/25/1996 Dupont 37 rue Murat 5/8/1997
Dupont 37 rue Murat 5/21/1996 Durnstein Thomashof 22 5/22/1997
Dupont 37 rue Murat 5/8/1997 Edwards 68 Downing Street6/27/1996
Durnstein Thomashof 22 5/22/1997 Gentil 17montee des Chenes
4/23/1997
Edwards 68 Downing Street 6/27/1996 Goldschmidt 91 Torre drive 4/1/1997
Gentil 17montee des Chenes 4/23/1997 Hopkins The Gables 5/23/1997
Goldschmidt 91 Torre drive 4/1/1997 Jones 34 Apple Grove 9/10/1996
Hopkins The Gables 5/23/1997 Kamata 70 Kiroto Street 9/8/1997
Jones 34 Apple Grove 8/12/1996 Kamimura 34 Kawasaki Avenue
6/15/1997
Jones 34 Apple Grove 9/10/1996 Keegan 10 Hamilton Park 8/4/1998
Kamata 70 Kiroto Street 8/1/1996
Kamata 70 Kiroto Street 9/8/1997
Kamimura 34 Kawasaki Avenue 5/3/1996
Kamimura 34 Kawasaki Avenue 6/15/1997
Keegan 10 Hamilton Park 12/15/1996
Keegan 10 Hamilton Park 8/4/1998

Copyright © 2000 Business Objects SA - All Rights Reserved


6
Tip 2: Correlated Subquery

Copyright © 2000 Business Objects SA - All Rights Reserved


7
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


8
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
Clickthe Table button
Select additional tables

Copyright © 2000 Business Objects SA - All Rights Reserved


9
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
Copyright © 2000 Business Objects SA - All Rights Reserved
11
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


12
Example Data(Chasm Trap)
Cust Id Order Id Order Date Order Value
10 18109 1/12/1999 10,000
10 20072 4/14/1999 15,000
10 20828 9/20/1999 18,000
28 18598 1/31/1999 12,000
28 20133 6/4/1999 4,000

Cust Id Cust Name


10 Paul
19 Mary
28 Cathy

Cust Id Loan Id Loan Date Loan Amount


10 190 8/5/1998 5,000
10 397 6/3/1999 10,000
19 236 12/13/1998 7,000
19 459 7/19/1999 2,000

Copyright © 2000 Business Objects SA - All Rights Reserved


13
Detail results
Cust Name Loan Amount Order Value
SELECT
Paul 45,000 86,000
Customer.cust_name,

Cust Name Loan Date Loan Amount Order Date Order Value Loans.loan_date,
Paul 8/5/1998 5,000 1/12/1999 10,000 sum(Loans.loan_amount),
Paul 8/5/1998 5,000 4/14/1999 15,000 Orders.order_date,
Paul 8/5/1998 5,000 9/20/1999 18,000
sum(Orders.order_value)
Paul 6/3/1999 10,000 1/12/1999 10,000
Paul 6/3/1999 10,000 4/14/1999 15,000 FROM
Paul 6/3/1999 10,000 9/20/1999 18,000 Customer,
Loans,
Paul’s totals incorrect Orders
WHERE
Loans should be 15,000 ( Customer.cust_id=Loans.cust_id )
AND ( Customer.cust_id=Orders.cust_id )
Orders should be 43,000 GROUP BY
Customer.cust_name,
Paul’s loans and orders displayed too many times Loans.loan_date,
Orders.order_date
Mary and Cathy missing from report

Copyright © 2000 Business Objects SA - All Rights Reserved


14
Tip 3: Chasm

Select the option Multiple SQL Only applies to measures. You force the SQL
Statements for Each Measure generation engine in Reporter to generate SQL queries
from the Universe Parameters for each measure that appears in the Query panel. You
dialog box. cannot use this solution to generate multiple SQL
statements for dimensions. Option is on by default.

Copyright © 2000 Business Objects SA - All Rights Reserved


15
Detail results – With Multiple SQL Statements
SELECT SELECT
Two SELECT statements generated
Customer.cust_name, Customer.cust_name,
Loans.loan_date, Cust Name Loan Date Order Date Loan Amount Order Value Loans.loan_date,
Orders.order_date, Paul 8/5/1998 1/12/1999 5,000 10,000 Orders.order_date,
sum(Loans.loan_amount) Paul 8/5/1998 4/14/1999 5,000 15,000 sum(Orders.order_value)
Paul 8/5/1998 9/20/1999 5,000 18,000
FROM FROM
Paul 6/3/1999 1/12/1999 10,000 10,000
Customer, Paul 6/3/1999 4/14/1999 10,000 15,000 Customer,
Loans, Paul 6/3/1999 9/20/1999 10,000 18,000 Loans,
Orders Sum: 45,000 86,000 Orders
WHERE Cust Name Loan Amount Order Value WHERE
( Customer.cust_id=Loans.cust_id ) Cathy 16,000 ( Customer.cust_id=Loans.cust_id )
Mary 9,000
AND ( Customer.cust_id=Orders.cust_id ) AND ( Customer.cust_id=Orders.cust_id )
Paul 15,000 43,000
GROUP BY GROUP BY
Customer.cust_name, Customer.cust_name,
Loans.loan_date, Loans.loan_date,
Customer totals report correct
Orders.order_date Orders.order_date

Mary and Cathy missing from detail report


Paul’s detail incorrect

Copyright © 2000 Business Objects SA - All Rights Reserved


16
Tip 3: Chasm

Define a context for each table In our example you could define a context from
at the "many" end of the joins. 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


17
Tip 3: Chasm

Define a context for each table Multiple SQL statements for each context must be
at the "many" end of the joins. selected. It is checked by default. If not you will receive
the “Incompatible Objects” error message.

Copyright © 2000 Business Objects SA - All Rights Reserved


18
Detail Results – Correct Using Contexts

Cathy

Loan Date Loan Amount Order Date Order Value


Sum: 1/31/1999 12,000
6/4/1999 4,000
SELECT SELECT
Sum: 16,000
Customer.cust_name, Customer.cust_name,
Orders.order_date, Loans.loan_date,

Mary sum(Orders.order_value) sum(Loans.loan_amount)


FROM FROM
Loan Date Loan Amount Order Date Order Value
Customer, Orders Customer, Loans
12/13/1998 7,000 Sum:
7/19/1999 2,000 WHERE WHERE
Sum: 9,000 ( Customer.cust_id=Orders.cust_id ) ( Customer.cust_id=Loans.cust_id )
GROUP BY GROUP BY
Customer.cust_name, Customer.cust_name,
Paul Orders.order_date Loans.loan_date
Loan Date Loan Amount Order Date Order Value
8/5/1998 5,000 1/12/1999 10,000
6/3/1999 10,000 4/14/1999 15,000
Sum: 15,000 9/20/1999 18,000
Sum: 43,000

Copyright © 2000 Business Objects SA - All Rights Reserved


19
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


20
Example Data(Fan Trap)

Order Id Product Quantity Sold Value


12345 BMW 3 160,000
Cust Id Customer Name Cust Id Order Id Total Value
12345 Kia 1 10,000
321 Dave 322 12345 550,000
323 554433 23,000 12345 Rolls 5 380,000
322 Paul
554433 Kia 3 30,000
323 Pete

Copyright © 2000 Business Objects SA - All Rights Reserved


21
Totals and Detail results
Customer Name Product Total Value Quantity Sold
Paul BMW 550,000 3
Both reports, summary Kia 550,000 1
Rolls 550,000 5
and detail, are incorrect Paul Sum: 1,650,000 9

Cust Name Total Value Quantity Sold Customer Name Product Total Value Quantity Sold
Paul 1,650,000 9 Pete Kia 23,000 3
Pete 23,000 3 Pete Sum: 23,000 3

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

Copyright © 2000 Business Objects SA - All Rights Reserved


22
Results

 Total Order Value per customer as well as


the Quantity sold
 Expected answer:
Paul $ 550,000 9 Cars
Pete $ 23,000 3 Cars
 Values returned when run in ONE SQL statement
Paul $1,650,000 9 Cars
Pete $ 23,000 3 Cars

Copyright © 2000 Business Objects SA - All Rights Reserved


23
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


24
Results – With Multiple SQL Statements

Totals Summary
Cust Name Total Value Quantity Sold
Paul 550,000 9
Pete 23,000 3
SELECT
SELECT
Customer.cust_name,
Customer.cust_name,
sum(Orders.total_value)
sum(Order_Lines.qty_sold)
FROM
FROM
Customer, Orders
Customer, Order_Lines, Orders
WHERE
WHERE
( Customer.cust_id=Orders.cust_id )
( Customer.cust_id=Orders.cust_id )
GROUP BY
AND ( (Orders.order_id=Order_Lines.order_id )
Customer.cust_name
GROUP BY
Customer.cust_name
Results are correct
But…………………..

Copyright © 2000 Business Objects SA - All Rights Reserved


25
Results – With Multiple SQL Statements
Detail Report
Cust Name Prod Id Total Value Quantity Sold
Paul BMW 550,000 3
Kia 550,000 1
Rolls 550,000 5
Paul Sum: 1,650,000

SELECT SELECT
Cust Name Prod Id Total Value Quantity Sold
Customer.cust_name, Customer.cust_name,
Pete Kia 23,000 3
Order_Lines.prod_id, Pete Sum: 23,000 Order_Lines.prod_id,
sum(Orders.total_value) sum(Order_Lines.qty_sold)
FROM FROM
Customer, Order_Lines, Orders Customer, Order_Lines, Orders
WHERE WHERE
( Customer.cust_id=Orders.cust_id ) ( Customer.cust_id=Orders.cust_id )
AND AND ( Orders.order_id=Order_Lines.order_id )
( Orders.order_id=Order_Lines.order_id )
GROUP BY
GROUP BY
Customer.cust_name,
Customer.cust_name,
Order_Lines.prod_id
Order_Lines.prod_id Detail results are still incorrect

Copyright © 2000 Business Objects SA - All Rights Reserved


26
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


27
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


28
Detail Results – Correct
Paul
Total Value Prod Id Quantity Sold
550,000 BMW 3
Two select statements produced
Kia 1
Rolls 5 Context used
Pete
Correct results
Total Value Prod Id Quantity Sold
SELECT
23,000 Kia 3
Customer.cust_name,
SELECT
Order_Lines.prod_id,
Customer.cust_name,
sum(Order_Lines.qty_sold)
sum(Orders2.total_value)
FROM
FROM
Customer, Order_Lines, Orders
Customer, Orders Orders2, Orders
WHERE
WHERE
( Customer.cust_id=Orders.cust_id )
( Customer.cust_id=Orders.cust_id )
AND ( Orders.order_id=Order_Lines.order_id )
AND ( Orders.cust_id=Orders2.cust_id and
Orders.order_id=Orders2.order_id ) GROUP BY
GROUP BY Customer.cust_name,
Customer.cust_name Order_Lines.prod_id

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

Copyright © 2000 Business Objects SA - All Rights Reserved


32
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


33
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


34
Step 1: Creating Summary Tables
 eFashion contains the following summary tables

Copyright © 2000 Business Objects SA - All Rights Reserved


35
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


36
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


37
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


38
Step 3: Define Incompatibilities
Ifclass shows an empty checkbox,
individual dimensions in that class
may be selected, ie. Store\State
Ifa class is selected, all objects in
that class are also selected, ie.
Product
Thisaggregate 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


39
Step 3: Define Incompatibilities

Thisaggregate 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


40
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


41
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


42
Step 5: Define Contexts (continued)
 The eFashion database with this new summary table

Copyright © 2000 Business Objects SA - All Rights Reserved


43
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


44
Step 5: Define Contexts (continued)
The Annual Shop Facts context…

…and the Shop Facts context

Copyright © 2000 Business Objects SA - All Rights Reserved


45
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 object’s status in a derived universe from the core
 Do not mix approaches

Copyright © 2000 Business Objects SA - All Rights Reserved


46
Tip 5: Linking Universes
 Three approaches
 ‘Kernel’  contains core common elements
 ‘Master’  contains all elements
 ‘Component’  merging universes
 General Designer Navigation
 Insert menu, select Universe to bring in the kernel universe
 Edit menu, select Links to alter linked universes
 ‘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


47
Tip 5: Linking Universes
Sales
 ‘Kernel’ approach
Kernel  ‘Kernel’ contains core common
HR
Kernel + elements
 Add specific components
Kernel +  Kernel of the linked universes
automatically updated
 Designer
 Bring in kernel universe
 Use table browser to add new tables
Kernel +  Join new tables into kernel
 Add new classes\objects from new tables
Only one level of
 Add new class\objects from kernel
linking allowed

Copyright © 2000 Business Objects SA - All Rights Reserved


48
Tip 5: Linking Universes
 ‘Master’ approach
Master
HR
 ‘Master’ contains all
Sales
 Hide unnecessary objects
Master - Master -  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


49
Tip 5: Linking Universes
 ‘Component’ approach
Part 1 Part 2
 Merging two or more universes into
Sales one
Part 1
 View several subuniverses as a whole
Part 2

 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


50
End of presentation

Copyright © 2000 Business Objects SA - All Rights Reserved


51

You might also like