Calculo para Un Hecho
Calculo para Un Hecho
Calculo para Un Hecho
Objectives
After completing this lesson, you should be able to:
Describe a calculation measure and its use in a business
model
Create calculation measures based on logical columns
Create calculation measures based on physical columns
Create calculation measures by using the Calculation
Wizard
Objectives
Calculations enable data to be processed to derive measures that are valuable in
analysis.
Business Problem
Businesses need to track the effectiveness of their
operations.
Businesses want to use businessrather than technical
language to ask business questions.
Example: Show me the accounts-receivable balance as of
Q3.
Business Problem
Businesses often want to compare values of a measure and need a calculation to
express the
comparison. For example, a business might want to compare the number of units
ordered
with the number of units that have actually shipped. The business might want to
see this
comparison in terms of actual units or a percentage. The business wants its users
to be able
to formulate business questions by using terminology that they understand.
Business Solution
Create calculation measures in the Oracle BI business model
by using the following methods:
Use the Expression Builder to create calculation measures
by using existing logical columns as objects in a formula.
Use the Expression Builder to create calculation measures
by using physical columns as objects in the formula.
Use the Calculation Wizard to create calculation measures
based on existing logical columns.
Add calculation measures to the Presentation layer so that
users can build analyses by using familiar terminology.
Business Solution
To meet the needs of various business measures, Oracle BI Server has a
calculation engine
to perform a multitude of calculations. Calculation measures enable users to make
inquiries
such as Show me the accounts-receivable balance as of Q3 or Show me the
difference
between units ordered and units shipped.
You can use the Expression Builder dialog boxes in the Administration Tool to
create
constraints, aggregations, and other definitions within a repository. The Expression
Builder
provides automatic color highlighting and other formatting enhancements to make
expressions easier to build and to read. The expressions you create with the
Expression
Builder are similar to expressions created with SQL. You can use all expressions
constructed
with the Expression Builder in SQL queries against the Oracle BI Server. You can
use
existing logical columns or physical columns in the expressions.
You can use the Calculation Wizard to create new calculation columns that
compare two
existing columns, and also to create metrics in bulk. It has a built-in mechanism to
handle
divide-by-zero and null cases, as well as other difficult situations. The Calculation
Wizard
provides an automated way to calculate the sales by quarter, the percentage of
revenue,
minimum and maximum values, and so on.
The methods for creating calculation measures are covered in detail in subsequent
slides.
Imagen 1
1. Create a New Logical Column
Start by creating a new logical column (DollarsperUnitsOrdered, in this
example) for
the fact table.
Imagen 2
2. Specify Logical Columns as the Source
On the Column Source tab, select the Derived from existing columns using an
expression
check box to specify that you want to use existing logical columns in the calculation
for the
new column.
3. Build a Formula
Open the Expression Builder and build the calculation formula
using existing logical columns.
Imagen 3
3. Build a Formula
In this example, you divide dollars by units ordered. If there are any aggregation
rules applied
to the logical columns, those aggregation rules are automatically applied in the
formula.
Both Dollarsand UnitsOrderedalready have SUMaggregation rules
applied. (Recall that
you applied these aggregation rules in an earlier lesson.) Thus the calculation
formula is
sum(Dollars)/ sum(UnitsOrdered).
After you finish, DollarsperUnitsOrderedappears as a logical column for
the Fact
Saleslogical fact table in the BMM layer.
Imagen 4
1. Create a New Logical Column
Start by creating a new logical column for the fact table. On the General tab, enter
a name
(Price UnitsOrdered, in this example). On the Column Source tab, ensure
that Derived
from physical mappings is selected.
yenny
2. Map the New Column
Use the Column Mapping tab of the Logical Table Source
dialog box to open the Expression Builder for the new column.
Imagen 5
2. Map the New Column
To map the new column, open the properties dialog box for the existing logical
table source
(Fact_D1_ORDERS2in this example). On the Column Mapping tab, make sure
that Show
unmapped columns is selected. Select the unmapped column, Price Units
Ordered,
and click the Edit Expression button to open the Expression Builder.
Imagen 6
3. Build the Formula
Using the Expression Builder, create the calculation formula by using the physical
columns
(PRICEand UNITORDDin this example). When you close the Expression Builder,
the
expression appears in the Expression field for the column on the Column Mapping
tab of the
Logical Table Source dialog box.
Imagen 7
Imagen 8
1. Open the Calculation Wizard
This slide shows how to start the Calculation Wizard. In this example, right-click
Units
Imagen 9
2. Choose the Columns for Comparison
The wizard prompts you to select the columns that you want to compare with
Units
Ordered. In this example, UnitsShippedis selected. Click Next to continue.
Imagen 10
3. Select the Calculations
The wizard prompts you to select the calculations that you want to model (Change
and
Percent Change in this example). The Calculation Wizard can create up to four
calculation
measures (Change, Percent Change, Index, and Percent). The wizard also
prompts you to
specify what value should be returned if the column has no value (null). This must
be
specified for all selected calculations. Select each calculation and specify what
value should
be returned. You can enter any numeric value or NULL. Do not enter a value that
would
change the data type. For example, do not enter NA, which is a character value
and not a
numeric value.
You can also change the calculation name at this point. This is the name that
appears in the
business model when the Calculation Wizard finishes. In this example, the
calculation
measure that calculates the difference between UnitsOrderedand Units
Shippedis
renamed CutsW.
Imagen 12
5. New Calculation Measures Are Added
When you click Finish, the new calculation measures are automatically added to
the business
Model
Imagen 13
Imagen 14
Examining a Query Using Physical Columns
You use physical columns for calculations that require that an aggregation rule be
applied
after the calculation. This slide examines the query log for a query that uses the
Price UnitsOrderedcalculation measure, which was built using physical
columns in
the formula. In this case, the SQL calculates the Units Ordered (UNITORDD)
multiplied by the
Price (PRICE), and then applies the SUMaggregation rule after the calculation.
The
calculation is expressed as sum(UNITORDD*PRICE).
This is easily determined by knowing when an aggregation rule is applied in the
calculation.
Use logical columns when the aggregation rule is applied before the calculation.
Use physical columns when the aggregation rule is applied after the calculation.
Imagen 15
Example: Using Physical Columns
In this example, the calculation measure TotalRevenueis based on physical
columns and
the aggregation rule is applied after the calculation.
Total revenue is derived by calculating, row-by-row, the unit price multiplied by the
units
ordered and then applying the SUMaggregation rule after the calculation to find
total revenue,
which equals $3,400 in this example.
What happens if the aggregation rule is applied before the calculation? In other
words, what
happens if you sum the unit price and units ordered columns first, and then you
apply the
calculation?
Applying the summation (aggregation rule) before the calculation produces the
following
incorrect results:
SUM(Unitprice): $500 + $400 + $300 = $1,200
SUM(Unitsordered): 2 + 3 + 4 = 9
$1,200 9 = $10,800
This calculation is not correct. Applying the aggregation rule (summing the unit
price column
and the units ordered column) before the calculation (unit price units ordered)
does not
accurately provide total revenue.
Imagen 16
Examining a Query Using Logical Columns
Use logical columns for calculation formulas that require an aggregation rule that is
applied
before the calculation. This slide examines the query log for a query that uses the
Dollars
perUnitsMeasuredcalculation measure, which was built using existing
logical columns
in the formula.
In this case, the SQL applies the SUMaggregation rule to UnitsOrdered
(UNITORDD) and
Dollars(DOLLARS) first and then calculates the division. This is expressed in the
example
in the slide as D1.c2/nullif(D1.c1,0).
The next slide provides further explanation of when to configure a calculation
measure based
on logical columns.
Imagen 17
Example: Using Logical Columns
In this example, the calculation measure UnitPriceis based on logical
columns; therefore,
the aggregation rule is applied before the calculation. UnitPriceis found by
applying the
SUMaggregation rule to both Dollarsand UnitsOrderedbefore calculating
the unit price
(dividing Dollarsby UnitsOrdered).
The advantage of defining a logical column formula based on existing logical
columns is that
you have to define it only once. When you define a formula based on physical
columns, you
must define a column mapping for each physical source from which the formula
can be
derived. However, sometimes you have no choice if you have to use physical
columns to
apply an aggregation rule after a calculation.
Imagen 18
Examining a Query Using the Calculation Wizard
When you use the Calculation Wizard to model calculation measures, it is
important to
consider that the wizard uses logical columns as objects in the calculation
formulation.
Therefore, an aggregation rule is applied before the calculation
Imagen 19
Using Functions to Create Expressions
To set up an expression using a function, select the Functions folder from the
Category pane,
select a function type from the Functions pane, and then select a function from the
lower
pane. Double-click the function you want to use to paste it in the edit pane. Then,
in the edit
pane, click once between the parentheses of the function to select that area as the
insertion
point for adding the argument of the function.
To paste a logical column at the insertion point, select the Logical Tables folder
from the
Category pane, select the table you want to use in the Logical Tables pane, and
then doubleclick
the logical column in the lower pane to paste the logical column at the insertion
point as
the argument of the function in the edit pane.
The screenshot shows an example of an expression that uses the RANKfunction.
The RANK
function is applied to the Dollarslogical column. The result shows total dollars
for each
product and each products rank in total sales.
Summary
In this lesson, you should have learned how to:
Describe a calculation measure and its use in a business
model
Create new calculation measures based on existing logical
columns
Create new calculation measures based on physical
columns
Create new calculation measures by using the Calculation
Wizard