# MDX Essentials: Logical Functions: The IsEmpty() Function - Page 4

November 1, 2004

We have now eliminated the display issue of percentage format, and have only to take the necessary steps to present "100%" as the percent of total on the Total Products line. Here we will use the ISEMPTY() function to remedy the problem (an error indicated in the cell value calculation) that is causing the nonsensical result of "1.#INF" to appear in the field.

The problem that underlies the appearance of the 1.#INF result is division by zero. The expression that makes up our calculated member (inside the WITH MEMBER clause we constructed earlier) is as follows:

```Measures].[Units Shipped]/([Measures].
[Units Shipped],[Product].Parent)```

The MDX above contains a .Parent function. This reference to the .Parent function works fine in the cases of each of the Product Families, because each of the families has a parent, the All Products level of the Product dimension. Total Products, however, which represents the All Product level itself, has no parent - All Products occupies the highest level in the dimensional hierarchy.

Because it has no parent, the value returned when we subject All Products to the .Parent function is null. Were this simply a reference to [All Products].Parent, an empty cell would be returned. However, when we use the reference within a calculation as a divisor, as we have done above, the result is effectively an attempt to divide by zero: MDX treats "null" as "zero," which causes the underlying error.

To eliminate the error, and to display the accurate value of "100.00%", we need to combine the IIF() function, which is employed to evaluate a conditional expression, with the MDX ISEMPTY() function, which, as we have noted, indicates whether a given value expression (in our case, a divisor of the expression forming our calculated member) is empty.

To meet the expressed needs of the information consumers with which we are working, we will take the following steps:

1.  Modify the WITH MEMBER, "AS" clause's contents, currently appearing as:

`   '[Measures].[Units Shipped]/([Measures].[Units Shipped],[Product].Parent)'`

to the following:

```
'IIF(ISEMPTY(
([Measures].[Units Shipped],[Product].Parent) ), 1,
[Measures].[Units Shipped]/([Measures].
[Units Shipped],[Product].Parent))'
```

Here we are simply surrounding the original string with An ISEMPTY() function, placing it into the parentheses to the right of the function (recall that, since we are referencing a tuple versus a simple member reference, we need two sets of parentheses: one for the function and one to enclose the tuple).

We enclose the ISEMPTY() function in the IIF() function. Within the resulting combination of the two functions and our references, we are saying, "if the tuple ([Measures].[Units Shipped],[Product].Parent) is empty, provide a 1 (which equates to 100 percent, when formatted); if the tuple is not empty, substitute the results of the calculation [Measures].[Units Shipped] / ([Measures].[Units Shipped],[Product].Parent."

IIF() is restricted to two numeric return values or two string return values (we cannot mix the two in a single use of the function), as we shall see in our next articles. We are working with numeric values here, where IIF() works well also because it cannot return null as a value (null is neither a string nor a numeric).

The Query pane appears as shown in Illustration 5, with additions circled in red.

Illustration 5: Modified Query in Query Pane (Compressed View)

2.  Execute the query by clicking the Run Query button in the toobar.

The Results pane is populated, and the dataset shown in Illustration 6 appears.

Illustration 6: Results Dataset, With the IIF() / ISEMPTY() Combination in Place

We can now see that our problem with the spurious data in the % Total Product column is a thing of the past. "100.00 %" is correctly reflected, thanks to our incorporation of conditional logic into the definition of the calculated member.

3.  Select File -> Save to save the query as MDX25-3.

4.  Exit the Sample Application when ready.

Thus we meet the business requirement through the use of the ISEMPTY() function, demonstrating a scenario where it helps to overcome presentation issues when empty cells are involved. In combination with the IIF() function, ISEMPTY() is a valuable tool we can use to test cells for emptiness, and to handle them when ISEMPTY() returns a positive for the empty state.

### Summary ...

In this article, we explored the ISEMPTY() function, whose purpose is to return a "true" if the expression to which it is applied evaluates to an empty cell. We noted that ISEMPTY() is an excellent means of identifying empty cells. We discussed the fact that empty cells are a common fixture of multidimensional sets, and then began a practice example that included the presence of such an empty, together with an undesirable consequence in the presentation of data to information consumers.

In addition to introducing the ISEMPTY() function in an exercise where we might see its value in managing empty cells, we introduced the IIF() function in the same example, combining the two functions to provide for the conditional application of our solution to manage an empty cell, as well as the divide-by-zero error that it brought into being. We examined the syntax surrounding the ISEMPTY() function, before beginning our multi-step practice exercise to illustrate the combined use of IIF() and ISEMPTY(). Moreover, we discussed the application of formatting our presentation to meet the needs of the intended audience. Finally, we discussed the results datasets we obtained in each of the steps of our efforts.

Discuss this article in the MSSQL Server 2000 Analysis Services and MDX Topics Forum.

MDX Essentials Series

×