Wednesday 23 April 2008

Database View and Custom Folders does not returns the same results in Discoverer

When running a workbook against a Database View with the same SQL as a Discoverer Custom Folder, the Workbook returns the expected results. If however, the same Workbook is built on top of a Discoverer Custom Folder, which is exactly a copy of the Database View, the value returned is different and it is not correct.

Changes

Here is an example of how to recreate the problem :
  1. Create the Database View :
    CREATE VIEW DISCO_CALCULATION_VW AS SELECT 1950 AS annual_hours , 52 AS period_divisor , 37.5 AS normal_hours , 10000 AS fte_annual_salary FROM dual

  2. Create a Discoverer Database Folder on this created View ;
  3. Create a Discoverer Custom Folder with exactly the same code ;
  4. On both the folder add the following Calculated Item :
    ( Normal Hours/Standard Hours )*Fte Annual Salary

    where
    Standard Hours = Annual Hours/Period Divisor

  5. Create a Workbook on both the Folders using Discoverer Desktop. The results for the calculated items will be different.

Cause

For the Workbook built on the Discoverer Custom Folder the sql executed is

"SELECT 1950, 10000, 37.5, 52, 1950/52, ( 37.5/1950/52 )*10000 FROM DUAL DUAL"

This means that the order given to the calculation is not working logically as expected and as returned in the database view.

Solution

To make the behavior to be the same on both the folders, the order of the calculation evaluated can be forced by changing the calculation from

"( 37.5/1950/52 )*10000"

to
"( 37.5/(1950/52))*10000"


which in turns began a modification of the Calculation item Standard Hours from :

Annual Hours/Period Divisor


to

(Annual Hours/Period Divisor)