Discoverer 4i Plus Online Help
Release 4.1


Contents

Index

Analytic Function Examples

Oracle Discoverer supports the Analytic Functions that are included in Oracle Server 8.1.6 and above. Discoverer also extends the functionality of standard SQL by allowing you to nest Analytic Functions. You can use these advanced functions to perform sophisticated analysis on your data.

This section contains the following sub-sections:

Analytic Function Categories

Analytic Functions are classified in the following categories:

Calculations and Drilling Into and out of data

When you use Analytic Functions, note that they have a precise definition which does not change as you drill, pivot, or sort the result set. For example, if you use the RANK function to assign ranks to sales figures partitioned by Quarter, if you drill down the Month level, the rank still only applies to the Quarter level.

About The Analytic Function Template

When creating Analytic Functions in Discoverer, you can either type or paste them directly into the Calculation dialog box, or you can select them from the function list.

If you select them from the function list, you are presented with a generic Analytic Function Template that helps you define the function by telling you what information you may need to provide. Templates should be used as a guide. Because templates are designed to cover most types of usage, you will not always need to use every part of the template.

For example, when you paste a new RANK Analytic Function into a calculation box, Discoverer provides the following template:

Although you can define a complex function using both expressions (expr1 and expr2), you can often define a simple function using only the ORDER BY expression; for example:

NOTE: By default, results data is sorted in ascending order (ASC), nulls first (NULLS FIRST).

For more information about expressions used by the Analytic Function template, refer to "More about the Analytic Function Template".

Ranking Function Examples

About Ranking

Ranking functions compute the rank of an item with respect to other items in an ordered list.

Assign Ranks to sales figures

This example ranks a set of sales figures.

Table 5-4 Workbook configuration for `Assign Ranks to sales figures'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Region, City, Sales SUM 

Sort Order 

Year, Region 

Conditions 

Department = Video Sale OR Department = Video Rental

Year = 2000 AND Region = Central 

Calculation Name 

Rank 

Calculation 

RANK() OVER(ORDER BY Sales SUM DESC) 

Notes 

By default, ranked results data is sorted in ascending order (ASC), nulls first (NULLS FIRST). The additional DESC parameter sorts the results in descending order, which ranks the highest value with the Rank 1. 

Display Data 

 

Assign Ranks to sales figures within Region

This example ranks a set of sales figures within each Region for each Year.

Table 5-5 Workbook configuration for `Assign Ranks to sales figures within Region'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Region, City, Sales SUM 

Sort Order 

Year, Region 

Conditions 

Department = Video Sale OR Department = Video Rental

Year = 2000 

Calculation Name 

Rank Top 

Calculation 

RANK() OVER(PARTITION BY Year, Region ORDER BY Sales SUM DESC) 

Display Data 

 

Show the top three selling Cities per Region

This example ranks a set of sales figures and displays the top three selling Cities for each Region.

Table 5-6 Workbook configuration for `Show the top three selling Cities per Region'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Region, City, Sales SUM 

Sort Order 

Year, Region 

Conditions 

Department = Video Sale OR Department = Video Rental

Year = 2000

Rank Top <= 3 

Calculation Name 

Rank Top 

Calculation 

RANK() OVER(PARTITION BY Year, Region ORDER BY Sales SUM DESC) 

Tip 

To quickly filter the list to the first, second, or third ranked cities, pivot the Rank Top item to the page axis. 

Display Data 

 

Show the top three and bottom three selling Cities per Region

This example ranks a set of sales figures and displays the top three and bottom three performing Cities per Region.

Table 5-7 Workbook configuration for `Show the top and bottom three selling Cities per Region'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Region, City, Sales SUM 

Sort Order 

Year, Region 

Conditions 

Department = Video Sale OR Department = Video Rental

Year = 2000

Rank Top <= 3 OR Rank Bottom <= 3 

Calculation Name 

Rank Top 

Calculation 

RANK() OVER(PARTITION BY Year, Region ORDER BY Sales SUM DESC) 

Additional Calculations Required 

Rank Bottom = RANK() OVER(PARTITION BY Year, Region ORDER BY Sales SUM ASC) 

Notes 

This analysis involves three steps:

1 - Assign ranks to Cities on Sales SUM in descending order, as Rank Top.

2 - Assign ranks to Cities on Sales SUM in ascending order, as Rank Bottom.

3 - Displaying only Rank Top, filter the data using a Condition to return only the top three and bottom three ranked Brands.

In the example shown below, in the `Central' Region, the top three cities are ranked 1, 2, and 3; the bottom three cities are ranked 5, 6, and 7.
In the `East' Region, the top three cities are ranked 1, 2, and 3; the bottom three cities are ranked 6, 7, and 8, and so on.
 

Display Data 

 

Banding Function Examples

About Banding

Banding is a type of ranking that divides a list of values in a partition into a specified number of groups called Bands (also known as buckets) and assigns each value to a Band.

Two common types of banding are:

Figure 5-2 Banding By Value



Use the GREATEST function or the CASE function to produce equi-width bands based on value.

Figure 5-3 Banding By Rank


Use the NTILE function to produce equi-height bands based on rank.

Producing equi-width Bands (1)

This example divides Sales figures into bands according to their value, (also known as equi-width bands).

Table 5-8 Workbook configuration for `Producing equi-width Bands (1)'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Region, City, Sales SUM 

Sort Order 

Year, Region 

Conditions 

Department = Video Sale OR Department = Video Rental

Year = 2000, Region = Central 

Calculation Name 

Sales Bands 

Calculation 

GREATEST(1,4-FLOOR((Sales SUM-Min Sales for Region)/GREATEST(1,FLOOR((Max Sales for Region-Min Sales for Region+1)/4)))) 

Additional Calculations Required 

Max Sales for Region = MAX(Sales SUM) OVER(PARTITION BY Region,Year)

Min Sales for Region = MIN(Sales SUM) OVER(PARTITION BY Region,Year) 

Notes 

Using the Central Region and Year 2000 as an example, this function takes the largest value (45,758) minus the smallest value (7,749) and divides it by four, ((45,758-7,749)/4), giving four equal Bands of 9,502.25. This gives four bands with the following ranges:

  • Band 1 - 36,255.75 to 45,758

  • Band 2 - 26,753.5 to 36,255.75

  • Band 3 - 17,251.25 to 26,753.5

  • Band 4 - 7,749 to 17,251.25

Each value is placed in one of the four Bands depending on which range the Sales SUM value falls into. 

Display Data 

 

Producing equi-width Bands (2)

This example creates the same results as the example in "Producing equi-width Bands (1)", except that it uses a CASE statement rather than the GREATEST function.
Again, the example divides Sales figures into bands according to their value, using a CASE function, (see also

Table 5-9 Workbook configuration for `Producing equi-width Bands (2)'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Region, City, Sales SUM 

Sort Order 

Year, Region 

Conditions 

Department = Video Sale OR Department = Video Rental

Year = 2000, Region = Central 

Calculation Name 

Sales Bands 2 

Calculation 

CASE
WHEN Sales SUM < Q1 THEN 4
WHEN Sales SUM < Q2 THEN 3
WHEN Sales SUM < Q3 THEN 2
WHEN Sales SUM >= Q3 THEN 1
END 

Additional Calculations Required 

MAX Sales = MAX(Sales SUM) OVER(PARTITION BY Year)

MIN Sales = MIN(Sales SUM) OVER(PARTITION BY Year)

Range = (MAX Sales - MIN Sales)/4

Q1 = MIN Sales + Range

Q2 = MIN Sales + (Range*2)

Q3 = MAX Sales - Range 

Notes 

This function uses a series of IF statements in the form of a CASE function to assign sales figures into bands, (see Band Ranges below).

 

Display Data

 

 

"Producing equi-width Bands (1)").

Producing equi-height Bands

This example assigns a set of sales figures into two equi-height Bands.

Table 5-10 Workbook configuration for `Producing equi-height Bands'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Region, City, Sales SUM 

Sort Order 

Year, Region 

Conditions 

Department = Video Sale OR Department = Video Rental

Year = 2000, Region = Central 

Calculation Name 

Sales Bands 3 

Calculation 

NTILE(2) OVER(PARTITION BY Year, Region ORDER BY Sales SUM DESC) 

Notes 

Using the Central Region and Year 2000 as an example, this function takes the number of values (which is six) and divides it by two, giving three values per Band. It then takes the list of values ordered by Sales SUM and places values one, two, and three in Band 1, values four, five, and six in Band 2. 

Display Data 

 

Windowing Function Examples

About Windowing

Windowing functions are used to compute aggregates using values from other rows. For example, cumulative, moving, and centered aggregates.

Two common types of windowing are:


Calculate a three month moving sales average

This example uses a logical window to calculate a moving three month Sales average.

Table 5-11 Workbook configuration for `Calculate a three month moving Sales average'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Month (Calendar Date Month), Sales SUM 

Sort Order 

Year, Month 

Conditions 

Department = Video Sale OR Department = Video Rental

Year = 2000, Region = Central 

Calculation Name 

Moving Avg 

Calculation 

AVG(Sales SUM) OVER(ORDER BY "Month" RANGE INTERVAL '2' MONTH PRECEDING) 

Notes 

Note that you define the RANGE INTERVAL as `2', not `3', even though you want a three month Window. This is because the Window expression implicitly includes the current row. Therefore, in this example, the INTERVAL `2' plus the current row gives a total of three months, (2 + current row = 3). 

Display Data 

 



Show the cumulative values of sales

This example uses a physical window to calculate the cumulative value of sales.

Table 5-12 Workbook configuration for `Show the cumulative value of sales'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Region, City, Sales SUM 

Sort Order 

Year, Region 

Conditions 

Department = Video Sale OR Department = Video Rental

Year = 2000, Region = Central 

Calculation Name 

Cumulative Total 

Calculation 

SUM(Sales SUM) OVER(ORDER BY Year ROWS UNBOUNDED PRECEDING) 

Display Data 

 



Reporting Function Examples

About Reporting Functions

Reporting functions are used to compute aggregates.

Calculate annual sales by Year

This example calculates annual sales by Year.

Table 5-13 Workbook configuration for `Calculate annual sales by Year'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Region, City, Sales SUM 

Sort Order 

Year, Region 

Conditions 

Department = Video Sale OR Department = Video Rental

Year = 2000 

Calculation Name 

Annual Sales 

Calculation 

SUM(Sales SUM) OVER() 

Display Data 

 

Calculate annual sales by region

This example calculates the total annual sales by Year and Region.

Table 5-14 Workbook configuration for `Calculate annual sales by region'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Region, City, Sales SUM 

Sort Order 

Year, Region 

Conditions 

Department = Video Sale OR Department = Video Rental

Year = 2000 

Calculation Name 

Annual Sales by Region 

Calculation 

SUM(Sales SUM) OVER(PARTITION BY Year, Region ORDER BY Year, Region) 

Display Data 

 

Calculate percentage of annual sales by Region

This example calculates the percentage of annual sales per Region for each City in each Year.

Table 5-15 Workbook configuration for `Calculate percentage of annual sales'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Region, City, Sales SUM 

Sort Order 

Year, Region, % of Annual Sales 

Conditions 

Department = Video Sale OR Department = Video Rental

Year = 2000 

Calculation Name 

% of Annual Sales 

Calculation 

Sales SUM*100/Annual Sales by Region 

Additional Calculations Required 

Annual Sales by Region= SUM(Sales SUM) OVER(PARTITION BY Year, Region ORDER BY Year, Region) 

Display Data 

 

Calculate sales as a percentage of total Sales

This example calculates sales as a percentage of total Sales.

Table 5-16 Workbook configuration for `Calculate sales as a percentage of total profit'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Region, City, Sales SUM 

Sort Order 

Year, Region, % of Annual Sales 

Conditions 

Department = Video Sale OR Department = Video Rental

Year = 2000, Region = Central 

Calculation Name 

% of total Sales 

Calculation 

RATIO_TO_REPORT(Sales SUM) OVER()*100 

Display Data 

 

Lag/Lead Function Examples

About Lag/Lead Functions

LAG and LEAD functions are typically used to compare values in different time periods. For example, compare sales figures in 2000 with sales figures in 2001.

Compare sales figures across time

This example compares sales figures across time.

Table 5-17 Workbook configuration for `Compare sales figures across time'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Sales SUM 

Sort Order 

Year 

Conditions 

Department = Video Sale OR Department = Video Rental

Region = Central 

Calculation Name 

Previous Year 

Calculation 

LAG(Sales SUM,1) OVER(ORDER BY Year) 

Notes 

Because there are no comparative figures for 1998, the Previous Year value for 1998 is blank. 

Display Data 

 


Calculate sales growth across time

Using the comparative sales figures from example "Compare sales figures across time", this example calculates the sales growth across time.

Table 5-18 Workbook configuration for `Calculate sales growth across time'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Sales SUM 

Sort Order 

Year 

Conditions 

Department = Video Sale OR Department = Video Rental

Region = Central 

Calculation Name 

Growth 

Calculation 

(Sales SUM-Previous Year)*100/Previous Year 

Additional Calculations Required 

Previous Year = LAG(Sales SUM,1) OVER(ORDER BY 'Year') 

Notes 

Because there are no comparative figures for 1998, the Previous Year value for 1998 is blank. 

Display Data 

 

Rank sales growth

Using the comparative sales figures from examples "Compare sales figures across time" and "Calculate sales growth across time", this example ranks sales growth by year.

Table 5-19 Workbook configuration for `Rank sales growth'

Select Items 

Video Analysis Information: Year (Calendar Date Year), Sales SUM 

Sort Order 

Year 

Conditions 

Department = Video Sale OR Department = Video Rental

Region = Central 

Calculation Name 

Rank Growth 

Calculation 

RANK() OVER(PARTITION BY Year ORDER BY Growth DESC) 

Additional Calculations Required 

Previous Year = LAG(Sales SUM,1) OVER(ORDER BY Year)

Growth = (Sales SUM-Previous Year)*100/Previous Year 

Notes 

Because there are no comparative figures for 1998, the Previous Year and Growth values for 1998 is blank and the Rank Growth is calculated as `1'. 

Display Data 

 


Statistical Function Examples

About Statistics Functions

Statistics functions are used to compute covariance, correlation, and linear regression statistics. Each function operates on an unordered set. They also can be used as windowing and reporting functions.

Calculate linear regression

This example computes an ordinary least-squares regression line that expresses the Profit SUM per Month as a linear function of its Sales SUM. The following functions are used:


Oracle
Copyright © 2000 Oracle Corporation.

All Rights Reserved.

Contents

Index