Some OBI EE Tricks and Tips in the Analysis Editor by Gerry Langton
By hamsun-Oracle on Jul 08, 2013
The following examples use the SUPPLIER2 database schema which is used in the Oracle University OBI EE training courses.
How to handle NULLs in a Pivot Table column
Sometimes you want to be able to display a value in a pivot table column even though there is no value in a column.
In this example we see that only one of our Sales Reps has actually sold any Frozen goods. As a consequence the Frozen column is blank for all the other reps. Putting a case statement in the Dollars column formula, e.g. CASE WHEN "Fact-Sales"."Dollars" IS NULL THEN 0 ELSE "Fact-Sales"."Dollars" END looks like a good bet. But unfortunately it doesn’t work as we don’t have a null value in the Dollars column. We just don’t have a row for this particular combination of Sales Rep and Product Type.
However we can use a little known feature of the column properties Data tab: you can enter a custom format that uses formatting commands similar to those used in Excel. The syntax used in this case would be:
positive-value-mask (semi colon) negative-value-mask (semi colon) null-mask.
For example #,###;-#,###;0
or #,###;-#,###;’No value’
So with that Custom Numeric format in place our Pivot Table now looks like this:
How to convert a string to proper case
Looking at the pivot table in the previous example we find the Sales Rep column in the Customers table is in upper case but we would like to see it reported with the first letter of each word in capitals and the remainder of the word in lower case. We review available functions in the Analysis Editor expression builder and don’t find anything suitable; however we know that Oracle provides the INITCAP database function which does exactly what we require.
The Analysis editor provides an EVALUATE expression which allow you to use database functions in the formula of a column.
The syntax for EVALUATE is:
EVALUATE('db_function(%1...%N)' [AS data_type] [, column1, columnN])
db_function is any valid database function understood by the underlying
data_type is an optional parameter that specifies the data type of the return result.
column1 through columnN is an optional, comma-delimited list of columns. Where column1 replaces %1 in the database function, column2 replaces %2 etc.
So we would type the following in the Sales Rep column formula:
Use of the EVALUATE function is disabled by default so you need to enable the feature in the NQSCONFIG.INI file and restart the OBI Server (via Enterprise Manager).
In the Server Section of NQSCONFIG.INI set the parameter EVALUATE_SUPPORT_LEVEL to either 1 or 2 as in the extract from the file below:
# 1: evaluate is supported for users with manageRepositories permssion
# 2: evaluate is supported for any user.
# other: evaluate is not supported if the value is anything else.
EVALUATE_SUPPORT_LEVEL = 1;
How to do Time Series calculations in the Analysis Editor
Whilst time series calculations can be created in the OBI Repository logical layer using Ago, To Date and Rolling Period functions, it is also possible to create new calculations ‘on the fly’ in the Analysis editor. When you look at the available functions for a column formula you will see ‘Ago’, ‘To Date’ and ‘Rolling Period’ etc. under the ‘Time Series’ heading. However ,the use of these functions is not particularly clear from the Online Help.
Let’s assume that the repository has been set up with a Time dimension which is called Dim-Time and a Time hierarchy called Time, and the Time hierarchy has levels ‘Year’, ‘Quarter’, ‘Month’ and ‘Day’.
According to the online Help, to use the To Date function we use the syntax:
TODATE(expr, time_level) . But what does time_level actually mean? Well we express the time level using the syntax: ‘time dimension’.’hierarchy’.’level’.
Assuming we wish to have year to date totals this would equate to “Dim-Time”.”Time”.”Year”.
So the formula for Year To Date Dollars would be:
TODATE(“Fact Sales”.”Dollars”, “Dim-Time”.”Time”.”Year”)
For Month Ago Dollars the formula would be: AGO(“Fact Sales”.”Dollars”, “Dim-Time”.”Time”.”Month”, 1), where 1 is the period offset, i.e. current month -1.
How to put an HTML link in the column formula
I was interested to discover that the Customer names used in our Oracle University OBI EE course database are in fact genuine American restaurants. I discovered this when I was playing around with the requirement to place HTML links into an Analysis, in this case to pass a column value into a Google search.
We can type the following into the formula of the Customer column:
'<a target="_blank" href="http://www.google.com/search?hl=en&as_epq=' || Customer.Customer || '&btnG=Google+Search">' || Customer.Customer || '</a>'
The first instance of the customer name (Customer.Customer) is passed to Google as the search string. The second instance is used to display in the Analysis.
The Google search string parameters used in this example are hl=en which sets interface host language to ‘en’, i.e. English and as_epq which specifies the whole phrase must be found, which is important in situations like this where there may be spaces in the column value.
Also check Custom Headings and put in a new heading for the column (otherwise it will display the html!)
Also check ‘Override Default Data Format’ and select HTML from the drop down in the column properties.
The Table view should look something like this and each customer name will be a link to Google Search, passing the customer name as a parameter.
So when you click on Alley-Cats for example you will find the restaurant in Arlington Texas.
One obvious problem you will encounter is that some of the Customer names
include an ampersand (&) character, and this is a terminator in the Google
search string. So when you click on ‘2nd & Goal Sports Cafe’,
only ‘2nd’ is passed to Google. To get round this you would have
to do a string replace, replacing the ampersand with ‘and’.
So the formula for the column would become:
'<a target="_blank" href="http://www.google.com/search?hl=en&as_epq='
|| REPLACE("Customer"."Customer",'&', 'and') || '&btnG=Google+Search">'
|| Customer.Customer || '</a>'
About the Author:
Gerry Langton started at Siebel Systems in 1999 working as a technical instructor teaching both Siebel application development and also Siebel Analytics (which subsequently became Oracle BI EE). From 2006 Gerry has worked as Senior Principal Instructor within Oracle University specialising in Oracle BI EE, Oracle BI Publisher and Oracle Data Warehouse development for BI.