IIF

Performs a conditional test, and returns an appropriate numeric expression or set depending on whether the test evaluates to true or false.

Syntax

IIF ( search_condition, true_part, false_part )
ParameterDescription

search_condition

An expression to evaluate as true or false (see MDX Grammar Rules).

true_part

A value_expression or a set. IIF returns this expression if the search condition evaluates to TRUE (something other than zero).

The value_expression can be a numeric value expression or a string value expression.

false_part

A value_expression or a set. IIF returns this expression if the search condition evaluates to FALSE (zero).

The value_expression can be a numeric value expression or a string value expression.

Example

Example 1

The company plans an expensive promotion of its caffeinated drinks. For the Caffeinated products only, the following query calculates a Revised Budget that is 110% of the regular budget.

WITH MEMBER 
 [Scenario].[Revised Budget] 
AS
 'IIF (
      [Product].CurrentMember.Caffeinated,
      Budget * 1.1, Budget
 )'
SELECT
 {[Scenario].[Budget], [Scenario].[Revised Budget]}
ON COLUMNS,
 [Product].Levels(0).Members
ON ROWS
FROM Sample.Basic
WHERE ([Measures].[Sales], [Year].[Qtr3])

This query returns the grid:

(axis)BudgetRevised Budget
100-101865020515
100-2089109801
100-3033703370
200-101106012166
200-20968010648
200-3038803880
200-4026602660
300-101060011660
300-2037604136
300-3082809108
400-1077507750
400-2068006800
400-3032903290
100-2089108910
200-2096809680
300-3082808280

Example 2

The following query calculates a Revised Budget equaling Budget for caffeinated products, and Actual for non-caffeinated products.

WITH MEMBER 
 [Scenario].[Revised Budget] 
AS
 'StrToMbr(IIF (
      [Product].CurrentMember.Caffeinated,
      "Budget" , "Actual"
 ))'
SELECT
 {[Scenario].[Budget], [Scenario].[Revised Budget]}
ON COLUMNS,
Children([100])
ON ROWS
FROM Sample.Basic
WHERE ([Measures].[Sales], [Year].[Qtr3])

This query returns the grid:

(axis)BudgetRevised Budget
Cola1865018650
Diet Cola89108910
Caffeine Free Cola33703189