- About the Series
- Introduction
- Introducing MDX Queries
- Key Concepts and Terminology
- Introducing Sets
- Understanding Metadata
- Working with MDX Queries
- Working with Member Sets
- Specifying Members in a Set
- Using the CrossJoin Function to Combine Multidimensional Sets
- Looking Ahead to Calculated Members
- Next in This Series
Looking Ahead to Calculated Members
We'll finish this lesson with a further enhancement to the query, and create a simple dynamic calculated member. (In a later article, we'll return to calculated members and expand their uses to include aggregation functions, along with an array of other uses for calculated members and calculated measures.)
We'll begin by changing the query from the previous example. The items to change are shown below in bold:
SELECT {[Store Cost], [Store Sales], [Unit Sales]} ON COLUMNS, NonEmptyCrossJoin([Store].[Store State].Members, [Product].[Product Family].Members) ON ROWS FROM Sales
Here's the new version we need. The changed items are again in bold:
SELECT [Measures].Members ON COLUMNS, NonEmptyCrossJoin([Store].[Store State].Members, [Product].[Product Family].Members) ON ROWS FROM Sales
In essence, we're changing the query to retrieve all measures as columns, instead of only the three measures specified earlier.
Change the query as indicated above. {[Store Cost], [Store Sales], [Unit Sales]} should become [Measures].Members.
Add comments, if desired, in the Query pane.
Save the query as MDX04-5.MDX.
Click the Run Query button. Figure 35 shows the results.
Figure 35 All measure members appear on the column axis.
Now we'll add a calculated member to provide an average revenue per unit figure that can be used in very rough comparisons between store states. But first, to see a calculated member in the Results pane, we need to make a further adjustment to the query.
Change the .Members part of the [Measures].Members expression to read .AllMembers. The query will now read as follows:
SELECT [Measures].AllMembers ON COLUMNS, NonEmptyCrossJoin([Store].[Store State].Members, [Product].[Product Family].Members) ON ROWS FROM Sales
Click the Run Query button. Figure 36 shows the results.
Figure 36 The calculated members appear on the column axis.
We now see the existing calculated membersall calculated measures (the most common type of calculated members), and therefore members of the Measures dimension. The .AllMembers function allows us to see these as well as the regular members.
Modify the query to add the Avg Rev Per Unit calculated member by placing the following statement in front of the existing query:
WITH MEMBER [Measures].[Avg Rev Per Unit] AS '[Store Sales]/[Unit Sales]'
Figure 37 shows the query's current format.
Figure 37 The modified query.
Click the Run Query button. Figure 38 shows the results.
Figure 38 The report with the new calculated member.
Our calculated member differs from the other calculated members shown earlier, in that our calculated member is dynamically created in the MDX query. The other calculated members were created in the cube structure, and are thus permanent and available for retrieval by any process with appropriate access.
Let's format (rounding to one-tenth of a cent) the annoying strings of digits spawned by the well-meaning sample application. Add the following instruction to the end of the WITH clause (the added expression is shown in bold):
WITH MEMBER [Measures].[Avg Rev Per Unit] AS '[Store Sales]/[Unit Sales]', format = '$ #,###.000'
Click the Run Query button. Figure 39 shows the final view of the report.
Figure 39 The report with the dynamic calculated member.
The exercises just completed should help to introduce you to the potential within the creation of dynamic calculated members, which can be extended to accomplish far more, including aggregation and other valuable reporting functions. The next article revisits calculated members for an in-depth examination.