Professional Documents
Culture Documents
When you create a KPI, you base one or more of your expressions on members in a measure group or
dimension. However, in some cases, the existing members dont support the type of KPI you want to create, at
least not in their current form. If thats the case, you can create a calculated member, which is similar to
creating a computed column in a SQL Server database.
To create a calculated member, open your Analysis Services project in SQL Server Business Intelligence
Development Studio (BIDS), and then open the cube in which you want to create your KPI. (For this article, Im
adding the KPI to the Sales cube.) In Cube Designer, click the Calculations tab, and then click the New
Calculated Member button. A new calculation form opens in the right pane, as shown in Figure 2.
Next, you should verify the setting for the Parent hierarchy property. By default, the property is set to
Measures. Because were creating a calculated measure, this is the hierarchy we want to use.
After you select the hierarchy, you must define an MDX expression that determines the value for your
calculated measure. In this case, I want to create a measure that provides the profit margin for each sale. The
following expression calculates the margin by dividing the net profit by the sales amount:
([Measures].[Sales Amount] ([Measures].[Total Product Cost] + [Measures].[Tax Amt] +
[Measures].[Freight])) /
[Measures].[Sales Amount]
Notice that I calculate the net profit by subtracting the total product cost, tax amount, and freight from the sales
amount. (You might decide on a different formula for you net profit.) I then divide that total by the sales amount.
Note: When opening the Calculations tab, you probably noticed the list of measure groups and dimensions in
the lower-left pane. You can drag a member from any of these hierarchies to your expression text box to add
the fully qualified name of that member to the expression. Also note, the MDX expression shown above is a
relatively simple one. You can, of course, create far more complex expressions. However, an in-depth
discussion about MDX is beyond the scope of this article. For more information about MDX, see SQL Server
Books Online.
After you create your expression for the calculated member, you can set additional properties. For this
example, I set the Format string property to "Percent" and then select Fact Internet Sales in the Associated
Measure Group property because I want to associate the calculated member with that measure group. Figure
3 shows what the form should look like after youve configured all the properties.
To configure the KPI, first provide a name. (I use Gross Profit for our example KPI.) Then select a value for the
Associated measure group property. (I use Fact Internet Sales.) Youre now ready to add the necessary
expressions to your KPI.
Case
When [Territory].[Sales Territory Group]
Is [Territory].[Sales Territory Group].[Europe]
Then .34
When [Territory].[Sales Territory Group]
Is [Territory].[Sales Territory Group].[North America]
Then .36
When [Territory].[Sales Territory Group]
Is [Territory].[Sales Territory Group].[Pacific]
Then .32
Else .30
End
Notice that I use a Case statement to define my criteria. The Case statement includes three When expressions,
one for each territory group. Each When expression identifies the member on which to base the expression and
the member value, following the Is keyword. This is followed by a Then expression which defines what action to
take. For example, the first When expression states that if the sales territory group is Europe, then the profit
margin goal is 34%. However, the goal for the North American group is 36%, and the goal for the Pacific group
is 32%. The Else clause then specifies that all other groups have a 30% goal.
After you add the status expression and set up the status indicator, your KPI form should look similar to the one
shown in Figure 5. (You have to scroll down to see the trend expression, which well work on next.)
For the Gross Profit example KPI, I use a trend expression that compares this years totals to the previous
year, as shown in the following Case statement:
Case
When IsEmpty(ParallelPeriod([Order Date].[Calendar Year].[Calendar Year],
1, [Order Date].[Calendar Year]))
Then 0
When [Measures].[Profit Margin] >
(ParallelPeriod([Order Date].[Calendar Year].[Calendar Year],
1, [Order Date].[Calendar Year]), [Measures].[Profit Margin])
Then 1
When [Measures].[Profit Margin] =
(ParallelPeriod([Order Date].[Calendar Year].[Calendar Year],
1, [Order Date].[Calendar Year]), [Measures].[Profit Margin])
Then 0
Else -1
End
Notice that the first When expression includes the IsEmpty function and the ParallelPeriod function. The
IsEmpty returns a value of true if the evaluated expression an empty cell value. Otherwise the function returns
false. I use this function in the first When expression to determine whether the year preceding the current one
exists in the cube data. If not, then the trend expression returns a 0, which indicates a neutral trend. (A trend
expression, like the status expression, should return a value from -1 to +1.)
The ParallelPeriod function returns a member value from a previous period thats in the same relative position
as the current member. Because I specify Calendar Year, the previous member will also be based on Calendar
Year. The function includes three arguments. The first argument returns the level of the hierarchy that you want
to target. In this case, its the Calendar Year level of the Calendar Year hierarchy, which is part of the Order
Date hierarchy. The second argument, 1, indicates the number of units that you want to go back. Because
Calendar Year is the current position, the function will go back one year. The final argument specifies that I am
basing the calculation on Calendar year. As a result, the first When expression in the Case statement above will
determine if the previous calendar year exists, and if it doesnt the trend will be set to 0.
The second When expression determines whether the profit margin for the current year is greater than the
profit margin for the previous year. Notice that the third argument in the ParallelPeriod function now specifies
Profit Margin, rather than Calendar Year. If the profit margin is greater in the current year, the trend value is set
to +1. However, the third When expression determines whether the profit margin for the current year equals
that of the previous year. If so, the trend value is set to 0. Otherwise the trend value is set to -1.
Notice also that you can set the trend indicator. You have three different types of arrows from which to choose.
Or you can pick the smiley face!
Display folder. The folder in which the KPI can be found when browsing the cube.
Parent KPI.> A KPI that acts as the parent of the current KPI so the parent KPI can use the value of
the child KPI.
Current time member. An MDX expression that returns a member that identifies the KPIs temporal
context.
Weight. An MDX expression that assigns a weight to a child KPI to indicate its relative importance in
the parent KPI.
After youve completed your KPI, you can then view its results, based on the current values in the cube data. To
view the KPI, click the Browser View button on the KPIs tab. The browser view includes two panes. The top
pane lets you define filters that determine what data the KPI uses, and the bottom pane displays the KPI. By
default (before any filters are defined), the KPI calculates the KPI value for the entire data set. However, you
can create filters that let you define the data for which you want to run the KPI.
For example, Figure 6 shows the filter I created for the Gross Profit KPI. I first selected Pacific as the sales
territory group, and then selected 2004 as the calendar year. As you can see in the figure, the KPI value is
29.72%. Because the goal for the Pacific group is only 32%, the Pacific group reached nearly 93% of its
goal for 2004, which means the status indicator is green. However, notice that the trend points downward.
Thats because they Pacific group did better in 2003 (30.58%).