Category Archives: Begin BI

Basic concepts to understand more on Business Intelligence

Cube Optimization Journal: Introduction

I have been working on cube optimization techniques for some time now. And honestly I even got my job for the same requirement. Its actually interesting to work with team of highly qualified MSBI professionals and learn new things on the same field, you were very confident about.

I am starting this as a journal and hoping to cover more and more on the topic gradually. In this way we can achieve a more strong foundation on this topic.

In this post we will cover the aspects where Cube optimization can be applicable/tested actually.

Following are areas we think of when we talk about cube optimization:

  1. Decreased usual size of cube: we often come in situation where cube is created and being used but it takes a lot of space on server. Cube optimization is mostly focused on decreasing the cube size which can lead to more efficiency in different other areas as well (listed below).
  2. Decreased processing time of cube: this one is a catch and we always want to achieve. Decrease in processing time can also impact in limiting space of cube, good reporting time, more frequency of data processing. Mostly due to longer time period of processing we decrease frequency of processing and users see a great latency in the report data (talking about MOLAP).
  3. Fast Reporting: Optimizing MDXs only in SSRS reports cannot give you fast report, it must come from real source “the cube”. And reporting like excel are only as fast as a cube is. We need faster reports for that we need a faster cube.
  4. “Can you think of any more valid reason anymore?”

Well we can talk about many other less important aspects like Loads on servers, better architecture blah blah . . .but what I believe is in project whats most important aspect is “Client” nothing else is significant more.

Client doesn’t care about populous server till he gets the result and damn if he care about your architecture if he doesn’t get the result he expected. Harsh but true :P.

So I hope using most important aspects for cube optimization. I will start with one of them to cover simple and effective optimization techniques.

Advertisements

Rank Functions in MDX

I know its looks weird to ask for Rank function”s” in MDX because there is only one for it.
But in SQL we have multiple Rank functions and used under different circumstances for solving different purposes. Those are RANK, ROW_NUMBER, NTILE and DENSE_RANK.

If SQL has it why not in MDX!!!! So I tried to give you few examples so that you can call the functionality of Rank functions of SQL in MDX. I saw few post online but those were so bloody complex that it took time for me to understand what they were trying to do, and yet not much useful.

Below is the Query with different calculated measures and then the screenshot from the result. Calculated measure names are actually based on T+SQL ranking functionality:


WITH

MEMBER [MEASURES].[SEM_COUNT] AS
COUNT(NONEMPTY([Date].[Calendar].[Calendar Semester].MEMBERS
,[Measures].[Order Count]) )
--This measure gives me repeating values and I needed same in
--showing example Rank

MEMBER [ROW_NUMBER] AS
RANK(([Product].[Category].CURRENTMEMBER
,[Product].[Subcategory].CURRENTMEMBER) ,
[Product].[Category].[Category]
*[Product].[Subcategory].[Subcategory]
)
-- Identity column for all the rows in result set

MEMBER [ROW_NUMBER_ORDER] AS
RANK([Product].[Category].CURRENTMEMBER,
ORDER([Product].[Category].[Category],[Measures].[Order Count], ASC))
-- To Replace ORDER BY of ROW_NUMBER in SQL by using MDX ORDER
-- it works same as expected, ranking of rows are done based on measure

MEMBER [ROW_NUMBER_PARITION] AS
RANK(([Product].[Category].CURRENTMEMBER,
[Product].[Subcategory].CURRENTMEMBER) ,
[Product].[Category].CURRENTMEMBER
*[Product].[Subcategory].[Subcategory]
)
-- To have a functionality of PARTITION BY in SQL, i built this example
-- where Ranks/ Row Numbers are given based on Category and Subcategory
-- it is not same as identity column as given above

MEMBER [RANK_DENSE] AS
RANK([Product].[Category].CURRENTMEMBER,
[Product].[Category].[Category]
)
-- It’s actually Dense Rank of SQL that we have RANK in MDX
-- Here we don’t do any manipulation and look we have a Dense rank for
-- for Categories
-- Important to Note is that Categories ranks are coming like 1,1,1,1 then 2,2,2,2
-- Not like 1,1,1,1 and 5,5,5,5

MEMBER [RANK] AS
RANK(([Product].[Category].CURRENTMEMBER,
[Product].[Subcategory].CURRENTMEMBER) ,
[Product].[Category].CURRENTMEMBER
*[Product].[Subcategory].[Subcategory]
, [MEASURES].[SEM_COUNT]
)
-- This is example for RANK in SQL
-- Important to Note is that if the measure value
-- are same for multiple rows then values will be like 1,1,1 then 4,4,6 . . .
-- which is expected from RANK function on SQL but here it is a bit complex
-- To get this we have to use Current Member and Measure in Rank properly

SELECT {[ROW_NUMBER],
[ROW_NUMBER_PARITION],
[ROW_NUMBER_ORDER],
[RANK_DENSE],
[RANK],
[MEASURES].[SEM_COUNT],
[Measures].[Order Count]} ON 0,

-- ORDER function below doesn’t impact anything for RANK measures.
ORDER ({[Product].[Category].[Category]}
* {[Product].[Subcategory].[Subcategory]}
, [Measures].[Order Count])

ON 1
FROM [Adventure Works]
-- Below filter I used to validate few points in Ranks of result set. You can
-- of course avoid.
WHERE [Date].[Calendar].[Calendar Semester].&[2008]&[2]

Result (click on image to enlarge)
Result: Rank Funcitons in MDX

So you can study the MDX and result from the post. Here I can explain in detail what I did in MDX for different cases but I believe these example are simplest I can come up with and can be understood easily. Still in case of any doubt or explanation needed please comment and I’ll be ready to help.

These example doesn’t have NTILE but I’ll try to get some time and add alternative for it later.