MDX Essentials: String / Numeric Functions: Introducing the IIF() Function - Page 2

December 6, 2004


The following simple example illustrates conceptually the operation of the IIF() function. (We will be doing a practice exercise in subsequent sections, but if you want to "test drive" a sample, you can certainly cut and paste, or type, the below into the MDX Sample Application).

We will query the Warehouse sample cube to determine, for operating year 1998, and for Canadian stores, which of the Foodmart organization's Hamburger brands were profitable at the Warehouse level. If profitable, we would like to assign a "1" to the calculated member "Profitability" that we will create for presentation purposes. We will display the Profitability calculated member next to the Warehouse Profit for each brand, to allow us to easily verify that the calculated member is functioning correctly.

   [Warehouse Profit]>0, "1", "0")'
   {[Measures].[Profitability]} ON COLUMNS,
   {[Product].[Product Department].
      Children} ON ROWS
   ([Store].[All Stores].[Canada],

This query returns a set similar to that depicted in Illustration 1.

Illustration 1: Returned Dataset for Example Query

We note that the returned data indicates that two hamburger brands, Gerolli and Ship Shape, were not profitable within the scope of Canadian stores in 1998. We used the "numeric option" in this illustration, as we sought to simply return a numeric value, 1 or 2, based upon whether each brand was profitable or not, respectively.

We will activate the concepts involved in the foregoing discussions by practicing the use of the IIF() function in the section that follows.