MDX Essentials: Basic Member Functions: The .Item() Function - Page 2August 9, 2004 PracticePreparation To reinforce our understanding of the basics we have covered so far, we will use the .Item() function in a manner that illustrates its operation. We will do so in simple scenarios that place .Item() within the context of meeting a business need. To begin, we will construct a SELECT query with a clearly defined set, then put .Item() to use in manipulating that set to meet the business needs of a group of hypothetical information consumers. The intent is, of course, to demonstrate the operation of the .Item() function in a straightforward manner. Let's return to the MDX Sample Application as a platform from which to construct and execute the MDX we examine, and to view the results datasets we obtain. 1. Start the MDX Sample Application. 2. Clear the top area (the Query pane) of any queries or remnants that might appear. 3. Ensure that FoodMart 2000 is selected as the database name in the DB box of the toolbar. 4. Select the Warehouse cube in the Cube drop-down list box. Let's assume, for our practice example, that we have received a call from the Finance department of the FoodMart organization, requesting some information surrounding units shipped for a given time frame upon which they plan to perform some basic analysis. The Finance information consumers specifically wish to know the total units shipped figure for the US store states, for each of the quarters of 1998, having become focused on this state / time combination initially to do some per unit analysis of various logistics costs. We will first create a basic query that returns the units shipped totals for each of the US store states, over the quarters under consideration. It is from the results dataset that is returned that the consumers state that they may want to narrow their request, once they get a look at overall figures, to more focused view(s) of specific state(s) only. Let's construct a simple query, therefore, to return the units shipped information, presented by quarters (as columns) and the store states (as rows). 5. Type the following query into the Query pane: -- MDX022-1, Preparation for Use of .Item() Function, Numerical Index, -- in a Basic Query SELECT {[Time].[1998].Children} ON COLUMNS, {[Store].[All Stores].[USA].Children} ON ROWS FROM [Warehouse] WHERE ([Measures].[Units Shipped]) 6. Execute the query by clicking the Run Query button in the toolbar. The Results pane is populated by Analysis Services, and the dataset shown in Illustration 2 appears. We see the four quarters of 1998 populating the columns across, and the Store States (from the Stores dimension) appearing on the row axis. 7. Select File -> Save As, name the file MDX022-1, and place it in a meaningful location. 8. Leave the query open for the next section. Next, let's say that our information consumers are provided with the full set of data that we have generated. They examine the metrics, and then request that we narrow the report scope to "Oregon-only" stores. We realize, from looking at our first results dataset, and perhaps in Analysis Manager, etc., that Oregon is the second of the three members of the tuple we have defined within our initial query. We decide that the .Item() function, with an index setting of 1 ("0" being the first member position, and "1" the second) will serve to generate the new limitation on the results. We take the following actions to meet the new consumer request: 9. Within the query we have saved as MDX022-1, replace the top comment line of the query with the following: -- MDX022-2, Use of .Item() Function, Numerical Index, in a Basic Query 10. Save the query as MDX022-2, to prevent damaging MDX022-1. 11. Append the .Item() function to the rows axis definition of the query, changing the following line: {[Store].[All Stores].[USA].Children} ON ROWS to the following {[Store].[All Stores].[USA].Children.Item(1)} ON ROWS The Query pane appears as shown in Illustration 3, with the new addition circled. 12. Execute the query by clicking the Run Query button in the toolbar. The Results pane is populated, and the dataset depicted in Illustration 4 appears. 13. Re-save the file as MDX022-2. 14. Leave the query open for the next step. We have used the .Item() function, in its member incarnation, with a simple numerical index. Let's see an example where we use a string within the index, based upon our original query above, where we selected all three store states. 15. Within the query we have saved as MDX022-2, replace the top comment line of the query with the following: -- MDX022-3, Use of .Item() Function, String Index, in a Basic Query 16. Save the query as MDX022-3. 17. Inside the parentheses of .Item() function, replace the existing numeral ("1") with the following string: "WA" The Query pane appears as shown in Illustration 5, with changes. 18. Execute the query by clicking the Run Query button in the toolbar. The Results pane is populated, and the dataset depicted in Illustration 6 appears. 19. Resave the query as MDX022-3, leaving the sample application open for the steps that follow. We deliver the new results to the Finance consumers, who accept our work thus far with stated satisfaction. They promise to "get back to us" with follow-up requests in short order. We next hear from a representative of Finance a couple of days later, with a request that contains elements similar to the specifications so far. The group needs the units shipped totals for the Washington stores, from the perspective of non-consumable goods sold only, for the first three quarters of 1998. We recognize instantly the opportunity, in this case, to combine both the member and tuple versions of the .Item() function into a single query, and set out to do so in the following steps. 20. Create a new query by selecting Query --> New on the Sample Application toolbar. 21. Type the following into the Query pane: -- MDX022-4, Use of .Item() Function, Member and Tuple (MultiString Index) SELECT {[Time].[1998].Children.Item(0): [Time].[1998].Children.Item(2) } ON COLUMNS, {CROSSJOIN([Store].[All Stores].[USA].Children, [Product]. [Product Family].Members).Item("[WA]","[Non-Consumable]")} ON ROWS FROM [Warehouse] WHERE ([Measures].[Units Shipped]) As we can see, we are using the member variation of the .Item() function to return the three quarters (indexes 0, 1, and 2, respectively), the range of which we manage conveniently with the colon (":") operator. In addition, we are using the tuple variation of .Item(), with multiple string indexing option, in the rows axis, where we are cross joining store states and product family. We comply with the rules for the multi-string index approach, in that we stipulate each dimension present in the tuple, in appropriate order, and so we obtain the desired results. (Try changing the order of the strings, or otherwise manipulate them, to see the results, as convenient). NOTE: For more information on the CrossJoin() function, see my Database Journal article MDX Essentials: Basic Set Functions: The CrossJoin() Function . 22. Execute the query by clicking the Run Query button in the toolbar. The Results pane is populated, and the dataset shown in Illustration 7 appears. 23. Save the file as MDX22-4. Summary ...In this lesson, we explored the MDX .Item() function. We discussed the tandem general objectives of the function, to return a member from a tuple, or a tuple from a set, and then we examined the syntax for each of the two variations. We then undertook illustrative practice examples of business uses for the .Item() function, generating queries that capitalized on its primary features. Finally, we briefly discussed the results datasets we obtained from each of the queries we constructed. » See All Articles by Columnist William E. Pearson, III Discuss this article in the MSSQL Server 2000 Analysis Services and MDX Topics Forum. MDX Essentials Series
The LEVEL_NUMBER Member Property
The LEVEL_UNIQUE_NAME Intrinsic Member Property Intrinsic Member Properties: The HIERARCHY_UNIQUE_NAME Property Intrinsic Member Properties: The DIMENSION_UNIQUE_NAME Property Further Combination of BottomCount() with Other MDX Functions Combine BottomCount() with Other MDX Functions to Add Sophistication Basic Set Functions: The BottomCount() Function, Part I Intrinsic Member Properties: The MEMBER_VALUE Property Intrinsic Member Properties: The MEMBER_UNIQUE_NAME Property Intrinsic Member Properties: The MEMBER_NAME Property Intrinsic Member Properties: The MEMBER_KEY Property Intrinsic Member Properties: The MEMBER_CAPTION Property Set Functions: The StripCalculatedMembers() Function Set Functions: The AddCalculatedMembers() Function MDX Numeric Functions: The Min() Function MDX Numeric Functions: The Max() Function Set Functions: The .AllMembers Function MDX Essentials: Set Functions: The MeasureGroupMeasures() Function String Functions: The .Properties Function, Part II String Functions: The .Properties Function Logical Functions: IsGeneration(): Conditional Logic within Filter Expressions MDX Scripting Statements: Introducing the Simple CASE Statement Logical Functions: IsGeneration(): Conditional Logic within Calculations Logical Functions: IsAncestor(): Conditional Logic within Filter Expressions MDX Clauses and Keywords: Use HAVING to Filter an Axis Logical Functions: IsAncestor(): Conditional Logic within Calculations Logical Functions: IsSibling(): Conditional Logic within Filter Expressions Logical Functions: IsSibling(): Conditional Logic within Calculations MDX Operators: The IsLeaf() Operator: Conditional Logic within Filter Expressions MDX Operators: The IsLeaf() Operator: Conditional Logic within Calculations MDX Numeric Functions: The .Ordinal Function Other MDX Entities: Perspectives MDX Operators: The IS Operator MDX Set Functions: The Distinct() Function MDX Set Functions: The ToggleDrillState() Function Set Functions: The DrillUpLevel() Function Set Functions: The DrillDownLevelTop() and DrillDownLevelBottom() Functions MDX Set Functions: DrillDownLevel() MDX Set Functions: The DRILLUPMEMBER() Function MDX Essentials: Set Functions: The DRILLDOWNMEMBERTOP() and DRILLDOWNMEMBERBOTTOM() Functions MDX Essentials : Set Functions: The DRILLDOWNMEMBER() Function MDX Essentials: Drilling Through with MDX: The DRILLTHROUGH Statement MDX Essentials: String Functions: The .UniqueName Function MDX Essentials: String Functions: The .Name Function MDX Essentials: String / Numeric Functions: The CoalesceEmpty() Function MDX Essentials: Basic Set Functions: The TopCount() Function, Part II MDX Essentials: Basic Set Functions: The TopCount() Function, Part I MDX Essentials: Enhancing CROSSJOIN() with Calculated Members MDX Essentials: Set and String Functions: The GENERATE() Function MDX Essentials: The CROSSJOIN() Function: Breaking Bottlenecks MDX Essentials: String / Numeric Functions: More on the IIF() Function MDX Essentials: String / Numeric Functions: Introducing the IIF() Function MDX Essentials: Logical Functions: The IsEmpty() Function MDX Essentials: Basic Set Functions: The EXTRACT() Function MDX Essentials: Numeric Functions: Introduction to the AVG() Function MDX Essentials: Basic Member Functions: The .Item() Function MDX Essentials: Basic Set Functions: Subset Functions: The Subset() Function MDX Essentials: Basic Set Functions: Subset Functions: The Tail() Function MDX Essentials: Basic Set Functions: Subset Functions: The Head() Function MDX Essentials: Basic Set Functions: The CrossJoin() Function MDX Essentials: Basic Numeric Functions: The Count() Function MDX Essentials: Basic Set Functions: The Filter() Function MDX Essentials: Basic Set Functions: The EXCEPT() Function MDX Essentials: Basic Set Functions: The Intersect() Function MDX Essentials: Basic Set Functions: The Union() Function MDX Essentials: Basic Set Functions: The Order() Function MDX Essentials - MDX Time Series Functions, Part III: The LastPeriods() and ParallelPeriod() Functions MDX Time Series Functions, Part II: The OpeningPeriod () and ClosingPeriod() Functions MDX Essentials - MDX Time Series Functions, Part I: PeriodsToDate() and Kindred Functions MDX Essentials: MDX Member Functions: "Relative" Member Functions MDX Member Functions: The Cousin () Function MDX Essentials: Member Functions: More "Family" Functions MDX Member Functions: The "Family" Functions MDX Essentials: MDX Members: Introducing Members and Member MDX Essentials : MDX Operators: The Basics MDX Essentials: Structure of the MDX Data Model MDX at First Glance: Introduction to SQL Server MDX Essentials |