Search code examples
ssasmdx

Are conditional scripts possible using MDX


In SQL the following structure is possible

IF <condition>
BEGIN
    <do something> 
END;

Can I use conditions in a similar way within MDX ?


EDIT
Specifically I'd like to somehow test if a set exists and use that as the condition in the IF statement.

IF TheFollowingReturnsRow(
          select * 
          from   $SYSTEM.MDSCHEMA_SETS
          where  SET_NAME = 'Set_Custom' and 
                 CUBE_NAME = 'MyCube') THEN
      <do something>
END IF

Solution

  • Depending on what you want to achieve, it is definitely possible to use IF statements in MDX:

    http://technet.microsoft.com/en-us/library/ms145517.aspx

    SCOPE ([Customer].[Customer Geography].[Country].MEMBERS);
    IF Measures.CurrentMember IS [Measures].[Internet Sales Amount] THEN this = 10 END IF;
    END SCOPE;
    

    Other alternatives include the IIF(Logical_Expression, Expression1, Expression2) and the CASE WHEN ... THEN ... ELSE ... END struct.