We are placing the ORDER() function within the curly braces, and placing the entire FILTER() function, put into place in our last set of steps, into the ORDER() function, as the set, or first entry, which is followed by the "order by" numeric expression and "direction." (We are breaking the hierarchy in our descending sort, to make the Stores sort in accordance with the requirements of the information consumers), ([Measures].[SalesPerSqFt]), BDESC).
Drawing close to the final version of our query, we have only to add formatting for our new calculated members, to make the data easier to understand for its eventual audience. We will accomplish this using the FORMAT_STRING, which we have exposed in several other articles of the series, as follows:
25. In the line under the AS keyword, (the line that is enclosed in single apostrophes), within the first WITH MEMBER clause, where we define the first calculated member, ApproxSqFootage, that is:
'IIF([Store].CurrentMember.Level.Name = "Store Name",
Val([Store].CurrentMember.Properties("Store Sqft")), 0)'
insert a comma (",") at the end of the line.
26. Insert the following in a new line, just beneath that in which we inserted the comma in the last step:
FORMAT_STRING = '#,##0'
27. In the line under the AS keyword, (the line that is enclosed in single apostrophes), under the second MEMBER keyword , where we define the second calculated member, SalesPerSqFt, that is:
'[Measures].[Store Invoice] / [Measures].[ApproxSqFootage]'
insert a comma (",") at the end of the line.
28. Insert the following in a new line, just beneath that in which we inserted the comma in the last step:
FORMAT_STRING = '$#,##0.00'
Within the definitions of both calculated members, we are simply inserting FORMAT_STRING to assign user-friendly formats (round numbers, with a comma thousands separator, for square footage Store Area, and currency presentation for the Sales per Square Feet value).
Our modified query appears, with the altered sections in red rectangles, as shown in Illustration 7.
Illustration 7: Modified Query in Query Pane (with Changes in Rectangles)
29. Execute the query by clicking the Run Query button in the toolbar.
The Results pane is populated with the DataSet depicted in Illustration 8.
Illustration 8: Results DataSet with ORDER() and Formatting Additions
A review of the DataSet at this stage reveals that we have succeeded in meeting the requirements expressed by the information consumers. While there are multiple ways to approach the delivery and presentation of a DataSet such as this, we have seen that, with only a few sequential steps, we can evolve a large data population into precisely the presentation that the intended audience requires. At the heart of our success in this example is the IIF() function, which, in conjunction with the VBA VAL() function and member properties, has facilitated the core data upon which the rest of the presentation depends.
30. Select File -> Save to resave the file MDX27-4 in its designated location.
In this article, we continued our examination of the IIF() function, which we began in String / Numeric Functions: Introducing the IIF() Function. Our goal in this article was to focus on additional uses of the function in a more involved practice scenario, whereby we could explore new considerations (such as the use of IIF() with member properties), while reinforcing concepts that we exposed in our introductory article. To achieve our objectives, we undertook a multi-step practice example aimed at providing a requested presentation of a specified DataSet, to support of the illustrative business requirements of a hypothetical group of information consumers.
After gaining an understanding of the business needs of the intended audience, we created a core query. We then sequentially evolved the specified presentation of the requested DataSet, discussing, along the way, the functions and methods we used and the results that we obtained from each. At the core of our solution lay the IIF() function, used in conjunction with a member property, whose data type we converted to make it useful in the context of the business needs of the consumers. We then filtered, ordered, and formatted our presentation to further comply with the requirements outlined.
» See All Articles by Columnist William E. Pearson, III
Discuss this article in the MSSQL Server 2000 Analysis Services and MDX Topics Forum.