Oracle BI EE 11g – Parent Child Hierarchies – Multiple Modeling Methods
As i had explained in my previous post here, Parent Child Hierarchies introduced in BI EE 11g are much more flexible in terms of handling aggregation of measures when compared with a Level Based Hierarchy. In this blog post, we shall see the various types of modeling techniques that we can use on a Parent-Child Hierarchy.
Lets take the example of a Staff Hierarchy in a Sales Department as shown below.
In a parent-child hierarchy, there are 4 different ways of modeling measures & attributes(using the Staff Hierarchy above as an example). They are
1. Modeling Staff Salary as an attribute - In this case, every Staff's Salary will be showed as an attribute and there will be no roll-up of the Salary data. Salary is at the same grain as the Staff.
-
Modeling Staff Salary as a measure - In this case, every Staff's Salary will be added to all his/her descendant's salary. When we are at the CEO level, we would like to know what is the total cost to the company because of the Salary offered to the employees. Salary is at the same grain as the Staff.
-
Modeling Staff Revenue as an attribute - In a sales department, even though there is a hierarchy, even a staff at the top level of a hierarchy can make a sale. Modeling as an attribute will show the Revenue figures contributed by that specific staff without any roll-ups from the bottom of the hierarchy.
-
Modeling Staff Revenue as a measure - In this case, every Staff's individual revenue contribution will be added to all his/her descendant's revenue contribution. This way, when we are at the CEO (or the top node) level, we can know overall revenue of the company. Revenue is at a lower grain than Staff.
BI EE 11g can quite easily handle all these types of aggregations. For the points 2 and 4 above, we can control the behavior of aggregation (roll-up only from children or all descendants etc). I have already blogged about it here. So, i will not be covering that in this blog post. Revenue is at a lower grain than staff.
To understand all the 4 points above, we need to understand our base tables first. We have one parent-child hierarchy table for Staff dimension, a closure table for the Parent-Child hierarchy and a Sales Fact table as shown below.
Case 1: Modeling Salary as an Attribute
In this case, only one step is required. We need to create a Staff dimension and then add a Closure table to the Parent-Child Hierarchy. Remember there are no physically defined joins between the Closure and the Parent-Child tables.
WITH SASUBWITH60281 AS (select MEMBER_KEY as c1 from GCBC_SALES.STAFF_CLOSURE T82195 where ( ANCESTOR_KEY = 'Edith Lofton' and DISTANCE = 1 ) ) select T82182.SALARY as c1, T82182.STAFF_NAME as c2, T82182.MANAGER_NAME as c4 from GCBC_SALES.STAFF_PARENT_CHILD T82182 /* Dim_STAFF_PARENT_CHILD */ where ( T82182.STAFF_NAME in (select D1.c1 as c1 from SASUBWITH60281 D1) )
Case 2: Modeling Salary as a Fact
In the above case, there is no aggregation applied on the Salary column. What if we want to roll-up the salary data from all the descendants. In order to do that, there are a couple of things that we will have to do. First one is to create an Alias for the Parent-Child table. This Alias will act as a Fact table.
a. Parent-Child table b. Closure table c. Parent-Child Fact Alias
In the first 2 cases, we had Salary at the same grain as the Staff. But in this case and the next, Revenue will actually be at a lower grain than the Staff. For example, a staff might get revenue for a company by selling multiple products at different points in Time. In this case, we shall see how to model Revenue coming from a Fact table to be modeled as an attribute i.e amount of revenue contributed by each staff.
To model this, we start with defining the joins. The only join we will need for this is an equi join between the Staff Parent-Child table and the SALES fact table. There need not be any join between the Closure table and the other tables.
In the previous case, revenue value of Pierre Houdan was 141. This is an individual contribution by him (consider a CEO himself closing a sale) towards revenue. But ideally, at the CEO level we would like the numbers to Roll-up thereby finding out the overall revenue contributed by all the staff as we upwards in the hierarchy. To model Revenue as a measure, we need to alter our joins as shown below for the following 3 tables.
1. Staff Parent-Child table & Closure table - Join on Child (staff) & Ancestor Key 2. Closure table & Fact Sales table - Join on Member Key and Child (staff)