Crystal Analysis in the Real World MDX
As mentioned in the previous section, the primary exposure that a Crystal Analysis designer has to MDX or Crystal OLAP Syntax is in the creation of custom calculations not already available in the data source. This section provides some real-world examples of MDX in action to facilitate some quick learning. Table 20.5 highlights a few sample calculations, their purpose and a quick explanation of their components.
Calculation |
Description |
MDX and/or Crystal OLAP Syntax |
---|---|---|
Member Name |
Often in Financial Reporting, the repetition of the Member Name is required in the middle of the worksheet (see Figure 20.19). This can be accomplished using the MDX CurrentMember and Name functions. In Figure 20.19, the caption has been changed to dashes for cosmetic reasons. |
KPI.CurrentMember.Name Crystal OLAP provides similar functionality with the GetName function. |
Variance |
The Variance function provided in the Calculation Expert uses the conditional IIF MDX function to check for null values and basic member syntax and math to calculate the variance. |
IIf( [Measures].[Budget] = NULL, NULL, (([Measures].[Actual]-- Measures].[Budget]) / Measures].[Budget]) * 100) |
Note that the sample OLAP cube already had a Variance calculation created but was re-created here to demonstrate the MDX. |
||
Growth |
The Growth function provided in the Calculation Expert provides a default growth calculation based on the growth of the current member (Q2 1998 in Figure 20.19) over the immediately previous member (Q1 1998) at that member's level in the hierarchy. In the example shown in Figure 20.19, this will not do because a Year over Year comparison is required. The default MDX provides a good starting point for modification. The original calculation used the PrevMember MDX function to capture the last Quarter. This needed to be replaced in the new calculation with a cocktail of MDX functions including Cousin, CurrentMember, Parent, and PrevMember MDX functions. |
The Default Growth Function MDX: IIf( [KPI].&[1] = NULL, NULL, IIf( Count( { ([KPI].&[1], [Time].PrevMember) } ) > 0, 100 * (([KPI].&[1]--([KPI].&[1], [Time].PrevMember)) / ([KPI].&[1], [Time].PrevMember)), 0)) |
The Edited Growth Function to Reflect Year over Year Growth: IIf( [KPI].&[1] = NULL, NULL, IIf( Count({([KPI].&[1], Cousin([Time].CurrentMember,[Time]. CurrentMember.Parent.PrevMember))}) > 0, 100 * (([KPI].&[1]--([KPI].&[1], Cousin([Time].CurrentMember, [Time].CurrentMember.Parent. PrevMember))) / ([KPI].&[1], Cousin([Time].CurrentMember,[ Time].CurrentMember.Parent. PrevMember))), 0)) |
||
Note that Cousin looks for the member at the same level of the first argument in the same relative position underneath the second argument's hierarchy. |
||
Parent Company Sales |
The LookUpCube function enables you to process an MDX statementon a separate cube within the same SQL Server database. In this hypothetical example, the Sales Report cube is accessed and Sales for All Products in the most recent year (using the LastChild MDX command) is reported back into this report. Now, you have the ability to perform more interesting financial calculations such as Contribution to Parent Company's revenues. |
LookupCube("Sales Reports", ([Products].[All Products], Year].[All Years].LastChild)") |
Note that members in the Sales Reports Cube that are not explicitly specified are set to their defaults. Ensure these are appropriate before completing a calculation. |
||
External Table Look-ups are not available in Crystal OLAP syntaxonly in MDX and SQL Server Analysis Services. |
Figure 20.19. This sample report available for download at UsingCrystal.com highlights the additional power MDX Calculations can provide to Crystal Analysis reports.
From the few examples highlighted, it should be clear that MDX and Crystal OLAP Syntax add a great deal of flexibility to your Crystal Analysis Reports. It also should have become evident that all the existing calculation experts are based on underlying MDX or Crystal OLAP syntax, and this is a great place to begin exploring the differing capabilities of these query languages.