Use of IF Statements

  • IF statement can be used in member formula; FIX cannot.
  • IF statement should be used within FIX statements to reduce the number of blocks that are to be accessed. The IF statement brings all blocks within the FIX into memory.
  • Where possible, use outer FIX statements on sparse dimensions and inner IF statements on dense dimensions.
  • Use ELSE instead of a combination of NOT and ELSEIF where possible to avoid unnecessary analysis of member values during the calculation. Do not use an ELSE statement if it is not required.
  • Review the Calc Member Block choice to determine if you can use a sparse member without dynamic calc dependencies.
  • Order IF statements, if possible, where the most number of cases hit the first IF in the block Use NOT within the IF to ensure this, if applicable.

    Consider the following script, which assumes that SalesYTD is a child of Ratios in Sample.Basic (where Accounts and Time are dense).

    SET UPDATECALC OFF;
    "SalesYTD"(
    IF(@ismbr("Jan"))
        "SalesYTD" = "Sales";
    Else
        "SalesYTD"="Sales" + @prior("SalesYTD");
    Endif)

    In this example, while 11/12th of data meets the ELSE condition, only 1/12th of the data meets the IF condition. Additionally, the SalesYTD member is calculated in Cell mode, which means that January, because it appears first in the outline, is calculated first regardless of the IF order. You can optimize this script by using NOT in the IF statement as shown in the following example:

    SET UPDATECALC OFF;
    "SalesYTD"(
    IF(NOT(@ismbr("Jan")))
        "SalesYTD" = "Sales" + @prior("SalesYTD");
    Else
        "SalesYTD"="Sales";
    Endif)