Thursday, March 13, 2008

Introducing OLAPTimeDimension for OLAP

In this sample though the data contained date information we didn't use it while building the OLAP cube. The reason was simple. The default OLAP implmentation in Flex 3 cannot handle dates in that format. It requires the date to be broken down into its components like year and month. If half year and quarter information is required that needs to be added to the flat data. That is a great pain point.

Here is OLAPTimeDimension to the rescue. It can be introduced as any other dimension in the OLAPCube schema and then configured to return year, half year, quarter, month and day in any combination.

<mx:OLAPCube id="salesCube" >

 <mx:OLAPDimension name="SalesData" >
   <mx:OLAPAttribute name="Company" dataField="company" />
   <mx:OLAPAttribute name="Region" dataField="region" />
   <mx:OLAPAttribute name="Market" dataField="market" />
   <mx:OLAPAttribute name="Product" dataField="product" />
    
   <mx:OLAPHierarchy name="Region-Market-Store" >
    <mx:OLAPLevel attributeName="Company" />
    <mx:OLAPLevel attributeName="Region" />
    <mx:OLAPLevel attributeName="Market" />
    <mx:OLAPLevel attributeName="Product" />
   </mx:OLAPHierarchy>
 </mx:OLAPDimension>
  
 <local:OLAPTimeDimension name="Years" dataField="date" />
  
 <mx:OLAPMeasure name="Revenue" dataField="revenue" />
  
</mx:OLAPCube>

Using this we get the following result where in we can query revenue for different years.

It can be easily extended to query quarters and months by setting includeQuarter and includeMonth to true on OLAPTimeDimension. The source is here.

6 comments:

Madhav said...

When I create a flex application in Flex Builder and paste the code for OLAPDemo3.mxml and OLAPDemo4.mxml, I get an error:

1180: Call to a possibly undefined method progress.

..at the line:

private var pbar:progress = new progress;

Of course, OLAPTimeDimension.as is present in the same folder as the mxml files.

Sreenivas said...

The progress.mxml file.

Unknown said...

I see progress only inside cubeCompleteHandler.

Is it possible to get the progress messages even for query execution just like we see for cube building?

I am delaying the pbar.closeWindow
until olapResultHandler but I dont see any progress messages after
var token:AsyncToken = cube.execute(query);

Sreenivas said...

If you have registered a event listener for CubeEvent.QUERY_PROGRESS you should get the progress of query execution. Let me know if that isn't the case.

Unknown said...
This comment has been removed by the author.
Unknown said...

Hi
I am facing a problem regarding Olap Datagrid creation onload of page. I am having dynamic data and query and cube is like the olap datagrid developed by you.
TypeError: Error #1009: Cannot access a property or method of a null object reference
at mx.olap::CubeNodeBuilder/findNodeWithOneCell()
at mx.olap:: CubeNodeBuilder/optimizeCube()

I am using Version no 3.0.0.47 of datavisualization.swc
I need to use this version only(no latest version).
I will appreciate your help.
Thanks