Thursday, October 15, 2015

OBIEE - Few options to compare data to previous month, Year or something...

I was asked to help with comparing data to previous period, month or year. There was another problem: No time dimension. I will describe here few options to do similar things.
(This post took me long time to finish. It started with 11.1.1.7 and was finished with 11.1.1.9 but should work with both)

Option 1: the correct option, use AGO function

This is the short and default answer. Create a date dimension. Make sure you have chronological key for at least date and month levels (date only might surprise you when comparing shorter and longer month) and use AGO function as described in the post: OBIEE and Time Series Calculations in analysis (Ago‎, Period Rolling‎, To Date‎).
For example:  AGO("Base Facts"."Revenue", 1)








The following options will be without time dimension. All done on analysis based on Sample Sales, with Product_Type, Revenue and some period (Year or Month or both).

 

Option 2: Calculating previous month using MSUM (relevant for non chronological as well)

The idea behind this option is the calculation: 
Sum(Last 2 Periods) = Previous Period + Current Period. As a result:

Previous Period = Sum(Last 2 periods) - Current Period

How do I calculate Sum(Last 2 Periods)? Using moving Sum. In our case: MSUM(measure,2)

Example 1: I have only Month and Revenue.
To calculate previous Month I add a column with formula MSUM(Revenue,2)-Revenue
Next I can do any calculation I want with the 2 columns.


Example 2: having Product Type, Month and Revenue 
When adding dimensions, things get a little complicated. I'll add "Product Type" column:
We have a problem with the first period. Instead of being zero or Null, it's the last value of the previous Product Type!

Since I'm lazy, I'll just add a case statement, for the first period of each product type, the value is NULL, else the previous calculation (just remember, first periods might be different for various Product Types).
First Period calculation: Min(Month by Product)
The case should be: CASE WHEN (Month=Min(Month by Product) then  NULL ELSE (MSUS(Revenue,2)-Revenue) END

Next I can do any calculation I want with the 2 columns.

By the way, some basic math using msum(Revenue,2):

Prev. period: msum(Revenue,2) - Revenue
diff between 2 periods: 2*Revenue - msum(Revenue,2) (the calculation: Revenue - prev. period)
% of change between periods: 100*(2- msum(Revenue,2)/Revenue) (the calculation: 100*diff/Revenue)


Option 3: Calculating same month of Previous Year

In many cases the data has strong seasonality, so it's logical not to compare and make calculations for the 2 month, but rather the same month of previous year.

To make things easier I used constant Years calculation. You can create a general analysis by replacing it with Presentation Variables or based on Current Year calculation:

Current Year:  YEAR(CURRENT_DATE)
Previous Year: YEAR(CURRENT_DATE) - 1

For this option to work I need the Month value to be the same for every year. In Sample Sales the month format is YYYY/MM, so I used the function RIGHT(Month, 2). Please note: in Sample Sales, both Year and Month columns are characters.

I filtered the data to be only Years 2009 and 2010.
Since I don't have a Year column. The initial data is sum of both years.


I'll add a column to calculate year 2010 Revenue only:  FILTER(Revenue USING (Year = '2010')) and one for Year 2009 FILTER(Revenue USING (Year = '2009'))

In case you have a presentation variable, named, for example, P_YEAR1 with the year 2010 selected, you should have the following formula: FILTER(Revenue USING (Year = '@{P_YEAR1}{2010}'))

Now we can remove the Revenue column and do any calculation we want with the 2 columns. (In the example bellow, I'm showing only fist 4 month of year and calculate the difference between the two years):


If you want a nicer column headers, but don't want them to be static... In case you use the analysis in a dashboard, you can use presentation variables as column names, such as: @{P_Year1}{2010} and use the same Variables as the analysis filter.


Option 4: Creating specific calculations using the $number calculated item (relevant for non chronological as well).

Assuming we want to compare specific values, lets say we want to compare 2 first month, 2 last month and last vs. first...
We can create a new calculated item and use $number to point to specific row / columns:
A useful and less known fact $-number would count from the end. 

 For example if we have 12 month in a pivot:

We can add calculated item that returns the difference between first 2 month: $2-$1
the last 2 month (if  I know they are 12 month)

Or if I don't know how many month they are ($-1 - $-2):


last month minus first month would be: $12-$1 (or $-1 - $1)...



Option 5: Using Filter to select specific periods (relevant for non chronological as well). Similar to option 3.

We can use filter function to return specific values.
For example we only want 2 first month of 2009 and the total revenue of 2009. I'll select the filter function:

Filter it by month:

select the condition:


and create the function:
the function is:
FILTER("Base Facts"."Revenue" USING ("Time"."Per Name Month" = '2009 / 02'))

We can replace the specific value (2009/02) with prompt.
Any calculation is now possible between the functions.

This will work if the aggregation level of the data is higher than the filter level. In our case a year:

Not if you add the month to analysis:





Option 6: Using Evaluate with the (Oracle) DB LAG function.


We can use database functions such as Lag and run them from Evaluate function in OBIEE. I leave it to you, if you are interested.

 

Thursday, September 10, 2015

OBIEE - Line Breaks

Customer asked for line breaks in analysis. This was basically covered before for example here by obiee10grevisited.blogspot.com but I felt it needs so more examples.
(done in OBIEE 11.1.1.7.140527)

Lets create a simple Analysis with 2 column, on of them the string I want line breaks in. The mark for line breaks in OBIEE is <br>. So my formula is: 'Hello<br>people'

This is the formula:

To force <br> to work we will set the text to be HTML in Data format:


Now we see it's working:

You might want the line break to work in the header as well. In that case, select the “contains HTML Markup” in Formula (or in Column Properties->Column Format) :

I was very much surprised to see the export and printing options handling this well not only in HTML output, but also in PDF:



In case your data does not contain <br> you can always use the replace function.

For example:

Replace('Hello !! People','!! ','<br>')

Special characters in data should work as well:

Replace('Hello'|| CHAR(13) ||'People',CHAR(13),'<br>')
 
 This kind of columns might cause some problems in Graph legends.

Wednesday, September 2, 2015

Oracle DB SE2 12.1.0.2.0 is available

Oracle DB Standard Edition 2 (SE2) 12.1.0.2.0 is available for download from Oracle here.The link to it's page is here.

At the moment it's available for the following platforms:
  • Microsoft Windows x64 (64-bit)
  • Linux x86-64
  • Oracle Solaris (SPARC systems, 64-bit)
  • Oracle Solaris (x86 systems, 64-bit)
  • HP-UX Itanium     
  • AIX (PPC64)
  • zLinux64
It is described as: 
Oracle Database Standard Edition 2 is an affordable, full-featured database built for unprecedented ease of use, power, and performance. From single-server environments for small business to highly distributed branch environments, Oracle Database Standard Edition 2 includes all the features necessary to build business applications.

  • Optimized for deployment in small enterprises, line-of-business departments, and distributed branch environments
  • Offers customers a container database architecture, making it easier to plug into the cloud
  • Includes rapid application development tools and supports a wide range of developer frameworks and data types including XML and JSON
  • Available on servers supporting a maximum of two sockets on all Oracle-supported operating systems, including Windows, Linux, and Unix
  • Provides complete upward compatibility, protecting your investment as your usage requirements grow

Tuesday, September 1, 2015

BDD 1.1 VM is availble as part of the Oracle Big Data VM

BDD 1.1 VM is available as part of the Oracle Oracle Big Data Lite Virtual Machine here, as part of the version 4.2.1.
Please note: This appliance is for testing and educational purposes only; it is unsupported and not to be used in production.  It includes software products that are optional on the Oracle Big Data Appliance (BDA), including Oracle NoSQL Database Enterprise Edition and Oracle Big Data Connectors (and now, BDD).