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.
Part I. Crystal Reports Design
Creating and Designing Basic Reports
Selecting and Grouping Data
Filtering, Sorting, and Summarizing Data
Understanding and Implementing Formulas
Implementing Parameters for Dynamic Reporting
Part II. Formatting Crystal Reports
Fundamentals of Report Formatting
Working with Report Sections
Visualizing Your Data with Charts and Maps
Custom Formatting Techniques
Part III. Advanced Crystal Reports Design
Using Cross-Tabs for Summarized Reporting
Using Record Selections and Alerts for Interactive Reporting
Using Subreports and Multi-Pass Reporting
Using Formulas and Custom Functions
Designing Effective Report Templates
Additional Data Sources for Crystal Reports
Multidimensional Reporting Against OLAP Data with Crystal Reports
Part IV. Enterprise Report Design Analytic, Web-based, and Excel Report Design
Introduction to Crystal Repository
Crystal Reports Semantic Layer Business Views
Creating Crystal Analysis Reports
Advanced Crystal Analysis Report Design
Ad-Hoc Application and Excel Plug-in for Ad-Hoc and Analytic Reporting
Part V. Web Report Distribution Using Crystal Enterprise
Introduction to Crystal Enterprise
Using Crystal Enterprise with Web Desktop
Crystal Enterprise Architecture
Planning Considerations When Deploying Crystal Enterprise
Deploying Crystal Enterprise in a Complex Network Environment
Administering and Configuring Crystal Enterprise
Part VI. Customized Report Distribution Using Crystal Reports Components
Java Reporting Components
Crystal Reports .NET Components
COM Reporting Components
Part VII. Customized Report Distribution Using Crystal Enterprise Embedded Edition
Introduction to Crystal Enterprise Embedded Edition
Crystal Enterprise Viewing Reports
Crystal Enterprise Embedded Report Modification and Creation
Part VIII. Customized Report Distribution Using Crystal Enterprise Professional
Introduction to the Crystal Enterprise Professional Object Model
Creating Enterprise Reports Applications with Crystal Enterprise Part I
Creating Enterprise Reporting Applications with Crystal Enterprise Part II
Appendix A. Using Sql Queries In Crystal Reports
Creating Enterprise Reporting Applications with Crystal Enterprise Part II