Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

oracle search

Showing posts with label AWM. Show all posts
Showing posts with label AWM. Show all posts

Monday, July 14, 2008

What no GUI? How to Load AW XML Files

This part of a series of postings prompted by many questions I received about how to manage an analytic workspace without using a GUI (AWM or OWB) . In this post I want to provide some more information on using XML templates. Most of this information came from Marty Gubar, OLAP Product Manager, who is an expert in using AW XML.

Personally, I am still not sure how you would create an XML file for an AW without using Analytic Workspace Manager, however, based on recent posts on the OLAP forum and from questions posted to our internal help mail list, it is obvious there are people actually designing and building AWs without ever using AWM. So I going to make the assumption that you have somehow managed to created your XML file that describes a dimension or a cube, or any other supported object, and question now is how do you load that file into the AW?

The first thing you need to do is to find this extremely useful jar file, called ImportXML.jar file. For the moment you will have to email me (keith.laker@oracle.com) to get a copy of this file, but hopefully the product management team will get it hosted on the OLAP OTN home page very shortly. Once you have this jar file you can create a script file as follows:

java.exe -classpath .\ImportXML.jar samples.awxml.ImportXML %1 %2 %3 %4 %5 %6 %7 %8 %9

The script takes the following arguments

  • id/pwd ID and Password
  • -con [host:port:sid] Connect string (e.g. localhost:1521:orcl)
  • -aw [TargetAW] AW that is the target for the XML input (required when XML does not include a complete AW)
  • - file [file] Name of XML file

Examples:
1. Importing an object (e.g. a calculation) into the GLOBAL analytic workspace:
  • import scott/tiger -con localhost:1521:orcl -aw global -file my_model.xml

2. Importing an entire analytic workspace:
  • import scott/tiger -con localhost:1521:orcl -file global_aw.xml

The above script can be used with the XML template files generated by Analytic Workspace Manager as well. Alternatively you can manually create your own (as some of you are quite clearly doing!). If you are manually creating these files, or just want to modify an existing file to make some changes hopefully the following overviews will help:

Structure of an XML File: Each XML file is broken down into four basic blocks, which relate to the type of work being performed.
  • Step 1 is to attach the required AW via an “Attach Id” tag.
  • Step 2 is to process the object identified within the file
  • Step 3 is to commit all changes
  • Step 4 is detach the AW
There is a quick an easy way to understand what is required and how these files are processed. If you use Warehouse Builder, it is possible to use Control Center to generate deployment scripts, which you can then review. For example I used OWB to generate a a CREATE dimension and a DROP dimension script so I could understand the steps involved and review the code it generated. There are a number basic tags that you need to use
  • Attach
  • Commit
  • Delete
  • Create
  • Delete
  • Alter
  • ActiveObject
  • Id
Hopefully, the following sections will help to explain how to use these various tags:

Attaching an AW
The process for attaching is very simple. There are two ways to do this, you either:
  • pass a parameter into your script file via the command line using -AW aw_name
  • code the AW and schema name into the XML file
I think the first is probably the best idea because it makes it easier to move XML and import files into different database instances. But if you want to hard code this information into your XML file then you need provide the following code:



(I am hoping you can read this code!). The process is quite straightforward. The first four lines are the normal XML header information, after that comes the following:
  1. Attach tag with an Id tag that contains an the word Action with a number, like this "Action1" . This controls the order of processing and in an normal XML file you will see this repeated with numbers increasing sequentially through the file
  2. ActiveObject tag starts the block to identify what the file is going to process which is determined by the next line
  3. In this case the attach needs to process an AW so an AW tag is used to identify the specific AW to be attached
  4. The last three rows contain the termination tags for rows 1,2 and 3.
It is possible to define an attach mode within this block as well, allowing the AW to only be attached in read-only mode which allows AWs to be shared across multiple projects and allows an AW to be attached by multiple processes at the same time.

Committing Changes within an AW
The process for committing is the same as the attach process except the tag Commit is used. Because during a session we could in theory have mulitple AWs attached the commit block still requires an ActiveObject block to identify the AW to be updated. This allows to not update other AWs as required.




Detaching an AW
The process for detaching is also the same as the attach process except the tag Detach is used. Because during a session we could in theory have mulitple AWs attached the detach block still requires an ActiveObject block to identify the AW to detach.



Building a CREATE Script
Create scripts are the output from Analytic Workspace Manager. After the main header block you will find a Create tag with an associated Id that defines the action reference for the create statement. If you are using the Attach tag as well, then the number associated with "Action" for the Create block must be greater than that used in the Attach block. It all sounds very complicated but when you see the code it is very simple.

The Create block identifies the create process in full. For a dimension that full process is:
  1. Dimension name
  2. Dimension labels
  3. Dimension attributes
  4. Dimension levels
  5. Dimension hierarchies
  6. Dimension mappings
A lot of information needs to be provided in the XML file, which is why I prefer to use Analytic Workspace Manager to generate these!

Building a DELETE Script
Performing a Delete operation in Analytic Workspace Manager is very simple - highlight the object and hit the delete key. Assuming there are no supporting objects that prevent the delete process from running the object will be deleted - for example you cannot delete a dimension while it is still associated with a cube. However, outside of Analytic Workspace Manager the XML file does provide a Delete tag to allow for command line deletion of objects. The amount of information you need to supply to delete an object is minimal. For a dimension it is simply the lines containing the Dimension tag and the end-Dimension tag. The delete process will remove all the objects with dimension automatically.








Building an ALTER Script
It is possible to update certain parts of an AW using this method. To be honest, I have not tried everything. According to the Java documentation this method allows you to update any of the text attributes, such as:
  • Long descriptive label
  • Short descriptive label
  • Plural descriptive label
So you could change a dimensions description from "Products" to "Company Products" for example. For more heavy duty alterations, such as modifying a hierarchy by changing the levels within the hierarchy I think you would need to delete the hierarchy first and then rebuild it. It may depend on the types of changes you want to make, however, the API documentation seems to indicate this is a heavily restricted tag. But enjoy!

OLAP Workshop Part 3 :Building an Analytic Workspace

OLAP Workshop Part 3 :Building an Analytic Workspace

In this lesson, we look at how to use the Analytic Workspace Manager 10g (AWM 10g) tool in conjunction with 10g OLAP to build multidimensional database objects. We will use AWM to perform the following tasks:

  • Create an analytic workspace
  • Define dimensions
  • Define cubes
  • Load data from source relational tables
  • View data
Throughout this post I have tried to add observations and best practices I have picked up while working with various customers across the US and EMEA. As a result I am going to split this posting into possibly three postings:
  • Create an analytic workspace and defining dimensions
  • Modelling and mapping different types of dimensions
  • Define cubes and load data from source relational tables
So what is the difference between AWM and OWB? AWM should be considered an “EL” tool, it does not contain transformation tools (in AWM 11g simple transformations are possible), for building analytic workspaces. .The target audience for AWM is business users and also developers already using another ETL tools that does not provide support for OLAP data modelling.

For this workshop we are going to focus on using AWM. For more information on using OWB to build OLAP data models see the links posted in Workshop 2.


Building Blocks of the Multi-dimensional Model







The first step is design the logical data model, including the dimensions and measures that are needed in the AW. Obviously Warehouse Builder provides the perfect environment for creating a logical data model, and there are some presentations that cover this on the OWB OTN Home.

However, if you prefer a more to use a pure data modelling tool then I would recommend looking at CWD4ALL from one of our partners, IKAN. To quote directly from their website:

CWD4ALL is a database & OLAP modeling and design tool, fully conformant to the OMG CWM™ specifications. Its advanced modeling and design capabilities provide the means to align your modeling activities with this new worldwide standard. CWD4ALL provides both forward and reverse engineering functionalities. Reverse engineering constructs a graphical model from your existing DB/2, UDB, Oracle and SQL Server 2000/2005 database or schema, which on their part can be forward engineered to an Oracle relational model and the corresponding DDL or Oracle Analytical Workspaces.

……

Multi-dimensional modelling and OLAP
The multi-dimensional model is integrated with the CWD4ALL data models, which stay on top them and use metadata from the logical model and therefore can be mapped to different implementations of relational models. Thus schema and naming independence for used tables and columns is provided, allowing a high flexibility during deployment of the model. Detailed and compact multi-dimensional diagrams provide an easy way to define dependencies in the multi-dimensional model even going beyond possibilities of traditional Star and Snowflake schemas. The multi-dimensional model provides support for OLAP & Oracle Analytical Workspaces. For relational data warehousing you will be able to deploy definitions of levels, dimensions and hierarchies to the Oracle dictionary, thus building a basis for the query rewrite option of the Oracle database. Moreover it will assist in building materialized view definition and defining bitmap join indexes. For Oracle OLAP data warehouse, CWD4ALL will deploy the multi-dimensional model to Oracle 10g Analytical Workspaces and assist in defining the SQL path to calculations in Oracle Analytical Workspaces through view definitions based on OLAP-TABLE functionality. In addition to designing and maintaining correct database relational model behavior, CWD4ALL allows the designer to examine and specify actual application behavior so that space management, undo datasets and the full range of implementation-specific parameters can be modeled and defined appropriately.

For more information on CWD4ALL click here to go to the website.

Obviously AWM can also help you design your logical data model but there is one important difference between AWM and OWB/CWD4ALL. AWM is best described as “design time at run time” which means as you create dimensions, cubes etc using AWM the object is created immediately in the analytic workspace, i.e. there is no deployment phase. Which from a business user perspective makes this an ideal product as it simplifies the whole process.

In this workshop we will create the following model based on the sales history schema (SH)

Dimensions
  • Time: Shows how data varies over time
  • Product: Shows how data varies by product
  • Geography: Shows how data varies by geography
  • Channel: Shows how data varies according to each distribution channel

Stored Measures
  • Sales
  • Costs
  • Quantity

Examining the Logical Model:
Dimensions
After you have identified dimensions, you can identify the levels of summarization within each dimension. Analysis requirements reveal that:
  • Channel dimension has three levels: Total, Class, and Channel
  • Geography dimension has four levels: Total, Region, Subregion, and Country
  • Product dimension has four levels: Total, Category, Subcategory, and Product.
  • Time dimension has three levels: Year, Quarter, and Month.
Note with OLAP dimensions and additional top level is always added to allow business users to fully analyse. In Excel terms this provides the “All” level, or in relational terms allows the dimension to be pivoted out of the query.

Cubes
Cubes provide a convenient way of collecting similar measures of the same dimensionality. It is not uncommon for many measures to have the same shape, and so by defining their shape (and other shared characteristics) for a cube, you can save time when building your AW. Multidimensional cubes are stored in AWs. A particular AW may contain more than one cube, and each cube may describe a different dimensional shape.

Dimensions defined the edges of a cube. Although there is no limit to the number of edges of a cube, BI tools typically organize the display along three edges: row edge, column edge, and page edge. A single dimension or multiple dimensions can be placed on each edge.

A cube is simply a logical object that helps an administrator to build and maintain an AW. It also aids in the definition of measures with common characteristics, such as sparsity patterns and aggregation rules. Measures in the same cube have the same relationships to other logical objects and can easily be analyzed and displayed together.

In this lesson, we will create our first cube, Sales, containing three measures. These are base measures, which store the facts collected about the business. Each measure that belongs to a particular cube shares particular characteristics with other measures in the cube, such as the same dimensions. The Sales cube includes:
  • Dimensions: Time, Geography, Product, and Channel
  • Measures: sales, costs, quantity
The data for these measures, and the dimensions that organize the measures, will be sourced from tables in the SH schema, as discussed in the next slide.

Getting Started
Configuring your database:
This is an area that seems to cause the most problems. This is always surprising to me considering that OLAP 10g is completely integrated into the database engine. The key here is making sure you have the correct patches applied to your database kernel and database instance. You can validate your existing configuration against the OLAP certification matrix, which can be viewed from here:

http://www.oracle.com/technology/products/bi/olap/collateral/olap_certification.html

When applying database patches please note that the majority of patches are composed of two parts. Firstly you need to use the Universal Installer to apply the kernel updates. Secondly your database instance needs to be upgraded via a series of SQL scripts. This is all documented but many people get caught out.

In this case I am using 10.2.0.3 version of the database (Note that OLAP is available only in the Enterprise Edition of the database and is a costed option) with an additional OLAP patched described as the “OLAP A Patch” in Metalink. All this is explained in the certification matrix as stated above.

You can quickly and easily check the status of your schema by connecting to your database instance using SQLPlus (or use SQLDeveloper) and run the following commands:

col comp_name format a25 heading 'Component'
col version format a12 heading 'Version'
col status format a10 heading 'Status'
col modified heading 'Modified'

SELECT comp_name, version, status, modified
FROM dba_registry
WHERE comp_name like '%OLAP%';

Component Version Status Modified
------------------------- ------------ ---------- --------------------
OLAP Analytic Workspace 10.2.0.3.0 VALID 19-NOV-2006 08:13:33
Oracle OLAP API 10.2.0.3.0 VALID 19-NOV-2006 08:13:35
OLAP Catalog 10.2.0.3.0 VALID 19-NOV-2006 08:13:38


Setting up AWM
The first step is to download AWM from the OTN OLAP home page:

http://www.oracle.com/technology/software/htdocs/devlic.html?url=http://download.oracle.com/otn/java/olap/AWM_102030A_Win32.zip

and the associated readme file that explains installation requirements is here:

http://www.oracle.com/technology/products/bi/olap/awm102030A_readme.html

After installing AWM you can run the awm.exe file located in the ..awm/bin directory or click on the desktop icon.








Making a connection to your database instance
The first step is to create a new user to own our analytic workspace. For this example we will create a user called SH_OLAP and this user will need to have a special role assigned to it to allow the user to create and manage analytic workspaces. This role is OLAP_USER. Some people are often tempted to use a different role, OLAP_DBA. This is similar to providing a normal user with the DBA privileges. Do not be tempted to use this role as provides a lot of additional privileges that can in some cases cause lots of problems during use. This role should only be assigned to the user OLAPSYS.

CREATE USER "SH_OLAP" PROFILE "DEFAULT"
IDENTIFIED BY "SH_OLAP" DEFAULT TABLESPACE "SH_OLAP"
TEMPORARY TABLESPACE "SH_OLAP_TEMP"
ACCOUNT UNLOCK;
GRANT "CONNECT" TO "SH_OLAP";
GRANT "OLAP_USER" TO "SH_OLAP";

This user will need SELECT priviledges on the source tables that will be used to populate the dimensions and the cubes.

As a best practice I will normally assign my OLAP user to its own tablespace and create a temp tablespace specifically for that user as well. The reasons for this will become evident later when we look at what happens during the loading of data into a dimension and/or a cube. Make sure this new user has sufficient quota on both these tablespaces.

When you start AWM for the first time you will need to define a new connection to your database instance.



This step can cause problems and a number of people have posted questions on the OLAP forum regarding connecting to a database instance. Using a TNSNames alias as the connection string causes the majority of problems. You can only use a TNS alias if you also install the SQL net layer from the database client CD. This is not provided as part of the AWM installation so needs to be added as part of a separate process.

Personally I always a JDBC connection as this does require any additional software to be installed. The syntax for a jdbc connection is :

Hostname:port:sid

An example would be something like this:

klaker-uk.uk.oracle.com:1521:beans

Alternatively you can use localhost or 127.0.0.1 to identify the host:


To now connect to our database instance simply click on “+” sign next to the database name. You will notice from the picture below you can define as many connections within AWM as you need. Once the connection dialog is shown enter the username and password in the dialog box. And then click OK to start the connection process.



Creating an Analytic Workspace
To create an analytic workspace, we need to perform the following steps:

  • Find the schema name under which you want the AW to reside, in this case our user is SH_OLAP. Expand that schema name to display the Analytic Workspaces node.
  • Next right-click the “Analytic Workspaces” node. This will show the “Create New Analytic Workspace” dialog box appears.
  • Lastly we can enter a name for our AW which in this case is SH_AW.

Optionally, we can choose a tablespace where this AW is stored. By default, the default tablespace is used for the schema. This is set up by the database administrator (DBA) when the schema is created. In this case the default tablespace is SH_OLAP.

Now we have created the AW, it appears in the navigator under the node where it is created. It is attached in read/write mode, which means that you can make changes to it.

At this point we have two options:
  • Manually define our dimensions and cubes
  • Load a predefined model from a template
You can create a workspace directly from a template. A template holds the definition of objects. You can use templates to create analytic workspaces, cubes, and dimensions. In this case we are going to manually define the objects within our AW.




Note: Once we have created the AW, a table named AW$SH_OLAP is created at the database level. (The format for the naming convention is AW$aw_name, WHERE aw_name is the name that you have chosen for your AW.) This table stores all of the multidimensional objects in your AW.

Does Oracle OLAP Support Multiple Languages?
Yes, an AW can support multiple languages. This enables the users of your OLAP applications and tools to view the metadata and descriptive attributes in their native languages.
The number and choice of languages is restricted only by the database character set and your ability to provide translated text. To add support for multiple languages, perform the following steps:
  • In the Model View navigation tree, expand the folder for the AW.
  • Click the Languages folder, and select the languages for the AW on
  • the General tabbed page.
  • As you create your objects, such as dimensions, levels, hierarchies, attributes, cubes, measures, calculated measures, and measure folders, open the Translations tabbed page of the property sheet. Enter the object labels and descriptions in each language.
When you map the dimensions, map the attributes to columns for each language.

Note: In this class, a single language is used, which is American, although the image shown below has multiple languages selected.




Creating Dimensions
Dimensions are lists of unique values that identify and categorize data. They form the edges of measures (facts). Dimensions have structure that helps in the navigation of data and the definition of calculations. This structure includes levels, hierarchies, and attributes in the logical model. You define these supporting objects, in addition to the dimension itself, in order to have a fully functional dimension.

Dimension Type
AWM provides two types of dimensions:
  • User Dimensions
  • Time Dimensions
Most dimensions that we will create during this workshop are of the type default “User Dimension”. In the example shown below, a Time dimension is created. If you explicitly set the dimension type to “Time Dimension,” AWM automatically prepares some additional time attributes. When populated, these attributes facilitate time series calculations on the measures that share this dimension. It is recommended that all your time dimensions be created with this setting.

Again this seems to regularly come up on the forums – you will only see the time series calculations in the Calculation Builder (See the workshop on building cubes). These calculations require two additional time based attributes to be populated – Timespan and End Date. Most customers do not have these attributes in their existing relational schemas so they need to be added. Fortunately OWB will generate an OLAP compliant time dimension. If you are not using OWB then you will need to find a different way of creating these additional attributes (there was a posting on the OLAP forum where someone actually posted all the code required to create an OLAP compliant time dimension but unfortunately I cannot find the thread now, may be someone else can locate it).



Other Tabbed Pages
The Translations tabbed page enables you to provide labels in languages that your AW uses:



The "Implementation Details" tabbed page enables you to identify certain dimension characteristics. By default I always recommend using the Surrogate Key option as this ensures unique members are created across all the levels within a dimension.




For people used to relational data models this can be quite confusing. What happens during when loading data into a dimension is all the source columns are collapsed into a single column within the AW. Therefore, across all the source columns the keys must be unique. Let’s consider an example with time:

YEAR_ID YEAR_DESC QUARTER_ID QUARTER_DESC MONTH_ID MONTH_DESC 31-12-2007 Yr 2007 31-12-2007 Q4 2007 31-12-2007 December 2007
Using this as a source table to populate our time dimension we have three keys (YEAR_ID, QUARTER_ID, MONTH_ID) that will be collapsed into a single column. It is obvious in this case the same key is used to identify three different levels within our dimension. In this case the last key that is read will win and the end result will be a single dimension member will be added to our time dimension and that member will be either a month or quarter or year (most likely a year). If we switch to using surrogate keys then three members will be added because the data load program will concatenate the level name with the source key to ensure uniqueness:
  • YEAR_31-12-2007
  • QUARTER_31-12-2007
  • MONTH_31-12-12007
Simple really! But does this have any impact on the AW? In some cases ‘Yes’. I have found that it is prudent to keep your level names as short as possible. When building levels I normally assign simple level names such as L1, L2, L3 etc etc. This keeps the surrogate keys small and compact. What I found working with one customer was that the OLAP engine had certain issues when using very large (75 characters) text strings as the source key and by adding the level to start of each key as well caused data loading problems. Probably an edge case but since then I have always preferred using simple level ids.

Creating Levels
For business analysis, data is typically summarized at various levels. For example, our database schema, SH, contains daily snapshots from a transactional schema (OE, HR, etc). Days are thus the base level. However, in this case the decision has been take to summarize this data up to the monthly level and then add quarterly, and yearly levels.

Levels have parent-child or one-to-many relationships, which form a hierarchy. For example, each month summarizes days, each quarter summarizes months, and each year summarizes quarters. This hierarchical structure enables analysts to detect trends at the higher levels and then drill down to the lower levels to identify factors that contributed to a trend.

To create a level for any dimension, right-click the Level icon beneath the dimension, and then select Create Level. Fill in the name, labels, and a description. The labels can be used in reports; the description enables you to comment on the object. Repeat the process for each level in the dimension.




The end result might look something like this (note I did not follow my own advice and created level names that are quite long, just to make it easier to explain certain steps in this workshop):





Creating Hierarchies
A hierarchy is a way of organizing dimension members. Oracle OLAP supports two basic types of hierarchy:
  • Value based
  • Level Based
In this workshop all the dimensions use level based hierarchies. This is where ordered levels are used as a means of organizing data. These hierarchies can be used to define data aggregation. For example, using our newly created Time dimension, we can define a hierarchy to aggregate data from the month level to the quarter level to the year level. This hierarchy can also be used to define a navigational drilldown path, regardless of whether the levels in the hierarchy represent aggregated totals.

Dimensions can have one or more hierarchies. If you define multiple hierarchies, make sure to define one of them as the default hierarchy.

As shown in the image below right-clicking on the hierarchy icon in the navigator provides a pop menu option to “Create Hierarchy”.



Name the hierarchy. We can provide descriptive labels that can be used in reports. Select the “Set as Default Hierarchy” option if this is the only hierarchy for the dimension or if it is the hierarchy that will be used most frequently for analysis. In this case we can choose the Level Based Hierarchy option.

Finally we can select the levels for our hierarchy. The levels are organized from the highest level of aggregation to the lowest.




Creating Attributes
Attributes contain descriptive information about dimension members that are used for data selection and identification. They are used for labelling cross-tabular and graphical data displays, selecting data, organizing dimension members, and so on. AWM 10g defines basic attributes automatically. For each dimension, it creates long and short description attributes. For a Time dimension, it also creates time-span and end-date attributes.

We can easily add additional attributes, such as month number or quarter number. These additional attributes further enrich the AW. The Implementation Details tabbed page identifies the data type for the attribute. This data type should match the source data.

For most attributes it is useful to consider creating an Index if the attribute has a reasonably low cardinality. This will improve query performance if the attribute is used as a filter within a business query. What happens under the covers is an additional dimension is created containing the members of the attribute and a relation is created to map the attribute dimension members to the base dimension members. Oracle OLAP is very efficient at using relations during queries as a way of filtering members.





In the next sub-section of this workshop (Workshop 3), we will review how to map dimensions to source data and how to manage different types of dimensions (value based, skip level, ragged, star source table and snowflake source tables).

Don't forget the other sections of this series:

OLAP Workshop Part 1 : Basic Overview of OLAP Concepts
OLAP Workshop Part 2 : Understanding OLAP Technology

Tuesday, June 17, 2008

Creating a Forecast using AWM 10.2.0.3 oracle

Building the Forecast
There are many reasons for recommending Oracle’s OLAP option within a data warehouse environment. The OLAP home page on OTN has presentations and technical white papers that help to explain these benefits. One of these benefits is the ability to support complex data models that are difficult to manage within a purely relational environment. For example, the creation of a forecast.

In the past I have presented many times at various Oracle user group conferences and OracleWorld sessions on how to use the results from a forecast within a BI Beans application, Spreadsheet Addin and Discoverer OLAP. But I have never gone into detail about how to actually create a forecast. Why? Because until now, you needed to have a deep understanding of OLAP DML and it was difficult to integrate the execution of the forecast into the normal procedures of building an analytic workspace.

With the release of AWM10.2.0.3 (you will need to apply the 10.2.0.3 patchset to your database which can be downloaded from Metalink) it is now possible to very quickly and easily create a new forecast without the need to have a deep understanding of the internals of Oracle OLAP or OLAP DML. If you do want to get a better understanding of the mechanics of building a forecast, the Help topics contained in Analytic Workspace Manager for OLAP DML provide some excellent examples of how to manually create a forecast and this will provide some insight into what is actually happening behind the scenes of AWM in the analytic workspace.

Creating a forecast is a very simple. But before you start you need to have additional time periods within your time dimension to hold the results of your forecast. This requirement will be familiar to Sales Analyzer customers. If you load the BI sample OLAP schema (SH_OLAP) you will notice the last year in the time dimension contains no data for any of the measures (revenue, costs and quantity). However, the first four time periods do contain data. Therefore, we can use the prior periods to compute new forecasted values for the last year in the time dimension.

The steps to create a new forecast are as follows:

1) Identify the measure you want to forecast and then create a new measure to hold the results of that forecast. For example, to create a forecast for sales revenue, add a new measure called Revenue Forecast to the Sales cube. You can create as many forecast measures, as you need. But remember a forecast measure must be in the same cube as the measure that will be used to source the data for the forecast. In this case since we want to forecast revenue, the forecast measure must be in the Sales Cube as this contains the source measure namely “Revenue”.



2) This new measure does not need to be mapped as the data will be sourced from existing revenue measure and calculated once the data for the revenue measure has been loaded.

3) Next create a new calculation plan to build and populate the forecast. In 10gR2 versions of AWM there is a new node in the Model view to manage calculation plans.



4) Defining the calculation plan is a two-stage process. The first part is to create the plan. This involves simply providing a name and corresponding labels. Each plan is then composed of a series of steps and there can be as many steps as required and the order of the steps can be controlled within the dialog.


5) There are three types of step: Aggregation, Allocate and Forecast. All these steps may be used when creating a forecast. Which steps are used to depends on how the forecast is created. Ideally the forecast should be generated at the lowest level for each dimension. But this may or may not be required. If this is not the case then before the forecast can be aggregated up the various hierarchies within each dimension the data has to be allocated down to the lowest levels. So AWM provides both “Allocation” and “Aggregation” steps to manage these operations.


To keep this simple, let us assume we are going to forecast data at the lowest level for each dimension in our Sales cube: Product, Channel, Geography and Time. First, a forecast step is created to generate the required data at the base level.

6) The New Forecast Step dialog is displayed. This panel contains three tabs:

  • General - controls the main inputs to the model, such as source measure, target measure, time dimension and type of forecast.
  • Advanced Settings – controls the parameters for the forecast model
  • Status - controls the dimension values that will be used to by the model



The various labels can be set to anything but it is useful to keep the information meaningful for future reference. The information entered here is not displayed to end-users;they will only see the measure we created in Step 1. These labels are purely for documentation purposes.

7) Next step is to select the cube (remember your target measure that is going to contain the forecast has to be in the same cube as the source measure). In this case we will use the SALES cube (dimensioned by Product, Channel, Geography and Time. It contains three measures: revenue, costs, and quantity. Plus the additional measure Forecast Sales).
8) Set the source measure to be Revenue
9) Set the target measure to be Revenue Forecast (as created at step 1)
10) The relevant Time dimension should be automatically selected.
11) Oracle OLAP supports a number of different forecast methods and if you have a good understanding of forecasting you can select the required method from the list in the pulldown. There is a description associated with each type of forecast to help you. However, the easiest method to use is the “Automatic” method. The forecast engine identifies the best fit by quickly testing each statistical method against the historical data. It selects the method that would have generated the most accurate forecast in the past. This method usually produces the most accurate short-term forecasts.


12) If you need to fine-tune the various parameters for the selected method, the Advanced Settings tab allows you fine-grained control to tweak these settings. Below are the settings for the “Automatic” method.



13) The last step on the General tab is to set the number of time periods for the forecast. In the common schema sample there are time periods (months and quarters and years) for five years within the time dimension, however, the last year does not contain any data. So there are 48 time months with data and 12 months without data. In this case, therefore, we set the number of time periods to forecast to 48. On the Status tab we will select the historical time periods and the forecast time periods and the forecast periods will be the last ones in status, based on the number specified on this page. As a result a forecast will be generated for the final year in the time dimension.
14) Switching to the Status tab allows us to define the dimension values to be used in the forecast. As stated earlier to keep this simple we will forecast data at the lowest level for each dimension. If you have used the Query Builder in BI Beans, or Spreadsheet Addin or Discoverer the next series of steps will be familiar to you as the selection process uses the same query builder panel (nice consistent look and feel and one of the benefits of reusable components).

For the Time dimension we will select to use values at the month level, as you can see the query builder panel makes it very easy to create this selection.




Repeat this step for each dimension. Once you have set the selections for each of the dimensions (Time, Channel, Geography, and Product), click the Create button to create the new forecast step.


15) Once this calculation plan is executed it will run a forecast for each product, within each channel, for each country, for each month and store the result in the new measure - Revenue Forecast. In addition, new revenue figures will be forecast for the last year in the time dimension.
16) However, at the moment the data for the forecast is only shown at the base level for each dimension. Therefore, another calculation step is required to roll-up the values so we can look at the forecast for All Products, All Channels, All Regions and across years. This is an Aggregation step.


17) This step allows us to define how the forecast measure should be aggregated. In this case the aggregation method will be the same as the other measures in the sales cube and the process for defining the aggregation step is almost the same as the process for defining a new cube.
18) Enter descriptive labels, then select the Sales Cube from the pulldown and then select Revenue Forecast as the measure to aggregate.


19) The “Summarize To” tab allows you to control which levels are pre-calculated as part of this process. As the sales cube is quite small and aggregated extremely quickly (a couple of minutes on my laptop) the best option is to select all the levels for each dimension.


Depending on the size of your cube and user expectations regarding performance you can tweak these settings to manage the amount of time it takes to create the forecast and aggregate the data. For example, if your forecast measure is taking a long time to aggregate you could try aggregating every other level. But make sure you always aggregate the top level.

20) Done! The completed panel should look the one shown below.



All that remains now is to execute this new calculation plan to generate the forecast data into our new measure.




Once the forecast has been executed and aggregated the results can be viewed in BI Beans, Spreadsheet Addin, Discoverer OLAP or BI Enterprise Edition.

Displaying the Results
To display the results of the forecast, it is useful to create a new folder and add the forecast measure to that folder. This makes it easier for users to find the new measure and makes it obvious the data is actually a forecast. In addition, it can be useful to create corresponding variance and % variance measures to allow users to compare the accuracy of the forecast to the base measure. Again these calculated measures could be added to the new forecast measure folder to make the easy to find.


Using Market Basket Analysis to add value to OLAP oracle

Anyone who has an interest in data warehousing and/or business intelligence understands the concepts of dimensions and hierarchies, which are key parts of a multi-dimensional model. In most cases the structure of a hierarchy is driven the corporate business environment. For example, if we consider the common schema (SH) that is shipped with the 10g version of the database, the product dimension has one single hierarchy that is based on normal business levels: Categories, sub-categories and products.

Regular readers of this blog will might remember a posting from last year where I explained how you could use attribute importance to help determine the most important dimensions within a cube. This posting uses another data mining feature to help business users analyse product groupings.

Most people are aware of the concepts of a shopping cart from buying products online, and it can be extremely useful to track the contents of these baskets. Each basket can provide valuable insight into customer buying patterns and provide the opportunity to identify options for cross selling. Therefore, to analyse customer-purchasing behaviour we need to extract the following information

  • Which product combinations are bought?
  • When they are purchased? and in
  • What sequence?
Using the information extracted from this analysis new product dimensions (or product hierarchies) can be created to track these baskets and provide business users with the opportunity to create new types of reports:
  • What are my top 5 baskets?
  • What are my bottom 5 baskets?
  • Which baskets are the most profitable?
  • How are my top 5 baskets performing in my key target regions
  • How have my top 5 baskets been performing over the last 2 years
  • What is the revenue forecast for next year for my top 5 baskets


One of the many benefits of Oracle’s 10g database is packed with features and the trick to getting the maximum benefit from the investment in Enterprise Edition is to make these features work together.

In this case we can use an association rules algorithm, part of Oracle Data Mining, to create an alternative product hierarchy that can be used to provide additional insight into business operations.

The association rules (AR) algorithm predicts the probability of co-occurrence among sets of attribute values. The most well-know use case for AR is market basket analysis, which predicts items occurring together in a market checkout session. This type of hierarchy can be used to help identify cross sell opportunities and product bundle strategies as well as product placement within online and the more traditional bricks and mortar stores.


Creating a Market Basket Analysis

Creating the association rules model
The sources for this example are the tables within the BI10g common schema. The SALES table contains point of sale data, which can be used as the main input to the market basket algorithm. To get started, you will need to have installed the Oracle Data Mining (ODM) Option (the default) during installation of the Oracle Database 10g. This ODM algorithm requires that the data be in this “transactional” format, with one item being represented in each row. This is an efficient representation, as any shopping basket will typically include several items from a possible hundreds or thousands of store items. The alternative, storing the data in a “single record per market basket”, would cause there to be hundreds to thousands of possible store items (attributes) with most of them being blank or null



Launch Oracle Data Miner client (for download details see the links at the end of this posting). Select Build from the Activity pull-down menu to launch the activity, and select Association Rules from the Function Type pull-down menu. Click Next.




The transactions (market baskets) are contained in the SALES table; select PROD_ID as the identifier for the items purchased. However, the products are identified only by an item code; the names of the products are in the PRODUCTS table, so click the checkbox indicating that there is a Name Lookup table, and select the table, the item identifier (PROD_ID), and the column containing the item description (PROD_NAME). This will then create meaningful product descriptions in the results table that can then used to populate the description for the dimension.

Click Next to continue.


Two columns are required to identify a single market basket. Click the checkboxes for CUST_ID and TIME_ID, then click Next.



The final step is to enter a name for the activity and click Next. On the final page of the wizard, click Advanced Settings to see the parameters available for Association Rules. In this case the default settings can be used. However, there are a lot of parameters that can used to tune the model. For more information regarding these parameters please refer to the documentation for Oracle Data Mining 10g Release 2. This can be downloaded from OTN.

Click OK to return to the last page of the wizard and click Finish to run the activity. When the activity completes, click Result in the Build step to access the rules defined by the model.


In this example, 115 rules were defined using the default parameter settings based on the transactions listed in the sales table



As well as the details of the products that comprise the rule two additional columns are provided: Confidence (%) and Support (%). The Support for the rule is the percentage of baskets containing the items in the rule. In the example, Support is the percentage of all baskets containing the three items mouse, keyboard and printer.
The Confidence for the rule is the percentage of baskets containing the item(s) in the antecedents that also contain the consequent. In the example, consider only baskets containing keyboard and mouse and calculate the percentage of those baskets that contain printers.

Saving the results
Finally, the results from the model can be published to a table. This table will then form the raw source for the new OLAP product dimension. Notice at this point there is no information relating to revenue, costs or quantity. All that information is already contained in the existing fact table that is used to feed the standard sales revenue, sales costs and sales quantity measures. All that needs to be done is to link the product bundles to the original fact table to extract the revenue, costs and quantity for each product within a bundle. The process for doing this will be explained later.







Designing the product dimension

The results from the algorithm table have to be transformed to provide a correctly formatted source for the dimension mapping. This requires the use of either OLAP DML (for those used to this powerful language) or PL/SQL. The aim is to create a new dimension table that confirms to the normal requirements for a source table. Therefore, a new top level has to be added to provide a total for “All Rules” and columns need to be populated for each of the attributes.

Each rule has to be broken down into its constituent parts:
  • The rule itself
  • The products that are part of the initial purchase
  • The products that are normally purchased in conjunction with the original items
From each rule the original product can be determined and referenced from the master Product Dimension.

This will allow us to track and analyze product bundles as part of the normal reporting process. Using the attributes associated with each rule, OLAP query steps can be created that further refine the analysis of product bundles by allowing business users to filter the results based on the value for % confidence associated with the rule.

In this example the decision has been taken to create a separate dimension to hold the results from the algorithm. The dimension is based around a single hierarchy with the following levels:
  • Top level – All Baskets
  • Rule – Rule derived from the algorithm
  • Group – Contains the IF and THEN parts of the rule
  • Product – Base product
In an ideal world, this information would be used to create a custom aggregate for each rule within the Product Dimension. However, although Discoverer for OLAP now supports custom aggregates there is no public API to help with the creation process. Therefore, the only way forward with this is to use a separate dimension to hold the rules.

This structure is outlined below with the associated attributes of:
  • Long description
  • Short description
  • Source product
  • Confidence %
  • Support %




The finished mapping looks like this:



Once the dimension has been maintained you can use the Dimension Viewer to check the results.


Designing the cube

The next requirement is to create a new source table that can be used in the mapping for the cube. Again some coding is required to create this new fact table. The code needs to extract the source products from each rule and identify the associated costs, revenue and quantity from the original fact table. This will then be moved to a new fact table to make mapping and loading data much easier to manager.

The new fact table looks like this:



When the cube is aggregated it will be possible to view the total revenue, total cost, total quantity, margin etc derived from the various products that are part of the rule.

A new cube called “MB” is created and the all the usual dimensions except in this case the new market basket dimension replaces PRODUCT dimension. The definition of the cube follows the same pattern as the other cubes in the sample schema.

In this case the figure for “All Baskets” which is the top level of the new market basket dimension is largely irrelevant. The reason for this is because the same product can appear in multiple rules, therefore, the value for total revenue, or total cost or total quantity is based on double counting of values. So this top value has to be treated with caution.

Now it is possible to create all the usual calculated measures for each of the base measures associated with a product bundle (revenue, costs, quantity, and margin) , such as those linked to the other cubes that are part of the common schema sample. For example:
  • 12 month moving average
  • 6 month moving average
  • Percent growth prior period
  • Percent growth prior year
  • Forecast
  • % Share of total revenue
  • % Share of total cost
  • % Share of total quantity
For the share calculations the formula needs to reach back to the original sales revenue cube that is dimensioned by the original product dimension. For this an OLAP DML formula is used which looks like this:

MB_REVENUE/SALES_REVENUE(PRODUCTS '1')*100

All these new measures can finally be added to a new measure folder called Market Basket Analysis and everything is ready for access by Discoverer OLAP, BI Beans and/or Spreadsheet Addin.

So what does this provide? With this cube it will now be possible to answer the following types of questions:
  • What are my top 5 baskets?
  • What are my bottom 5 baskets?
  • Which baskets are the most profitable?
  • How are my top 5 baskets performing in my key target regions
  • How have my top 5 baskets been performing over the last 2 years
  • What is the revenue forecast for next year for my top 5 baskets

Viewing the Results in Excel

Using Spreadsheet Addin it is now possible to connect to the updated schema. Launching the query builder shows the new dimension (Product Market Baskets) and the associated new measures for the market basket analysis



With this new dimension it is now possible to analyze the performance of each basket in the context of % growth prior period, % growth prior year etc. An obvious report to create is to show the performance of the top 5 baskets based on % growth prior year for year 2000, within the USA across All Channels.




The results from this query can be plotted on a line graph to show the revenue trend over the last 8 quarters as shown below.




Links
To help you get started creating your own market basket analysis here are some links that might be useful:

Data Mining
Oracle Data Mining on OTN:
http://www.oracle.com/technology/products/bi/odm/index.html

Oracle Data Miner Client on OTN:
http://www.oracle.com/technology/products/bi/odm/odminer.html

Data Miner Client software:
http://www.oracle.com/technology/software/htdocs/devlic.html?url=http://download.oracle.com/odm/odminer/odminer10203/odminer.zip

Data Miner Client installation instructions:
http://www.oracle.com/technology/products/bi/odm/odminer/odminer_install_10202.htm

Data Miner Tutorial
http://download.oracle.com/odm/odminer/odminer_tutorial_10201.zip

OLAP
Oracle OLAP on OTN:
http://www.oracle.com/technology/products/bi/olap/olap.html

Analytic Workspace Manager software:
http://www.oracle.com/technology/software/htdocs/devlic.html?=http://download.oracle.com/otn/java/olap/AWM102030_Win.zip

Analytic Workspace Manager demo:
http://www.oracle.com/technology/products/bi/olap/viewlet/AWM102_viewlet_swf.html

Oracle OLAP Spreadsheet Addin on OTN:
http://www.oracle.com/technology/products/bi/spreadsheet_addin/index.html

Spreadsheet Addin software:
http://www.oracle.com/technology/products/bi/spreadsheet_addin/download/index.html