Hello All,
We will continue with the KPI topic further trying to consider some complex scenarios.
In case you want to know about the KPI basics, you can visit the earlier post at http://vivekrohra.blogspot.in/2014/03/kpikey-performance-indicators-ssassql.html
So in the last post, we saw what are KPI's, what are actual value, Goal, Status and Trend of KPI.
Now Goals/Target is something that companies define for a period of time. It may be for a period of month or quarter or a year.
In last post, we took example for goal defined over period of year. So each year,goal changes.
But the expression used to define kpi goal for each year was case expression where goal value was mentioned for each year. This is hardcoding which makes life difficult in long run as there are lot of KPI's company has and as time progresses, case statement has to be modified to include goal values for new year.
So I create 2 new tables in the warehouse, dimension table for KPI and fact table for KPI Goal.
I have added one primary key called KPIKey in DimKPI table which will have integer values like 1,2,3..
The other column is KPIName.
Now, data is populated in DimKPI

The FactKPIGoal table will have the goal values for each KPI and period.
KPI_Goal will store the goal value. KPIKey is foreign key to table DimKPI.
DateKey is foreign key to DimDate.
So assuming the example in previous post, KPI is defined for each year. But to link FactKPIGoal and DimDate, DateKey has to be used which is at date level. So in FactKPIGoal, we will just take first date of each year in DimDate and will populate goal data in FactKPIGoal for the DateKey for that Date. This will get clear with the sample data populated.
In previous post, goal expression used was:
CASE
WHEN [Order Date].[Date Hierarchy].currentmember IS
[Order Date].[Date Hierarchy].[Calendar Year].&[2006]
THEN 0.54
WHEN [Order Date].[Date Hierarchy].currentmember IS
[Order Date].[Date Hierarchy].[Calendar Year].&[2007]
THEN 0.34
WHEN [Order Date].[Date Hierarchy].currentmember IS
[Order Date].[Date Hierarchy].[Calendar Year].&[2008]
THEN 0.25
ELSE 0.70
END
So while joining DimDate and FactKPIGoal, for year 2006, there should be just one record in FactKPIGoal. If i have one more record for another DateKey of 2006 in FactKPIGoal, cube will sum up the goals for both records when we browse the cube at the Year level which we don't want.
That is why we are taking first DateKey of each year and populating goal data in FactKPIGoal.
Now, its time to add the tables in the Cube. To do that, first add them in the Data Source View(DSV).
Then add the dimension by right clicking dimensions in Solution Explorer.
Select DimKPI table from DSV as source for new dimension. Keep KeyColumn as KPIKey as it is the primary key in the table and NameColumn as KPIName. NameColumn is the value that will be displayed to the user.
Select the attributes which needs to be shown in Dimension. In our case it is just one.
Now, dimension is added to the database. But I need to add it in the cube. Go to Cube, Right Click Cube Name in Dimensions tab and Click Add Cube Dimension.Select DimKPI from the list shown on next pop-up.

Let's now add the FactKPIGoal to the measure groups in the cube.

Now, since we are using Order Date dimension to view the KPI Goals, we need to specify relationship between Order Date dimension and FactKPI Goal measure group in Dimension Usage Tab.Both are linked by DateKey columns in both table.
Now, we create new KPI by going to KPI tab in the Cube.

As you can see above, the Goal Expression is ([Measures].[KPI Goal],[Dim KPI].[KPIName].&[1])
so it is getting the goal value for Profit % KPI which has KPI Key 1.
The Display Name will be Profit %( as the NameColumn specified earlier was KPIName) but the way cube stores it is [Dim KPI].[KPIName].&[1]( as the KeyColumn specified earlier was KPIKey).
So now KPI is defined, deploy and process the cube.
Now we will go to excel and connect to the cube.
I have selected the KPI which was created in Last Post( Gross Profit) and the one created now(GrossProfitDynamic). I have taken the Order Date hierarchy at year level.
As I have defined goals for 3 years(2006,2007,2008) , I am able to see goals for those 3 years in KPI GrossProfitDynamic while in KPI Gross Profit we had else statement in case where we had mentioned if it is any other year apart from the above 3, put goal as 0.7
Now if I have to Add goal for new year, I need not go to cube and modify case statement. I will add the data in FactKPIGoal table in the database.
As you can see above,I have added Goal value for year 2013 in FactKPITable.
Now just process the cube.
Now refresh the data in excel and here it is, the goal value pops up for year 2013.
I hope you gained some knowledge out of it. But to make things more complex, what if i have my company in different countries and now I have to populate KPI goal for each Year and each country.
Get your Thinking Hats ON :-)



















