IF_ELSEIF

English (Español a continuación)

I. Introduction

IF_ELSEIF is a conditional structure: if the condition is met, an action is performed; if it is not met, another action is taken.

  • Budget(
    • IF (@ISMBR (“January”))
    • 200;
    • ELSE
    • 100;
    • ENDIF
  • )

If the member being calculated is «January» the budget is 200; if it is not, the budget is 100.

II. Structure

Its structure begins with IF and ends with ENDIF.

  • Each condition is enclosed in parentheses.
  • Each action ends with «;»

This structure can be included in a calculation script or in a formula associated with a member in the outline.

  • If it is used in a script, the entire structure is included in parentheses and associated with a member of the outline (in the previous example “Budget”). Another member of the same dimension could also be used to open the structure. For example:
    • Sales (
      • IF (@ISMBR (“January”))
      • Budget = 200;
      • ELSE
      • Budget = 100;
      • ENDIF
    • )
  • In a formula associated with a member of the outline, do not include it in parentheses, and do not start it by indicating that member of the outline. For example, in the previous case we could associate this formula to the member of the outline “Budget”; the structure would be:
    • IF (@ISMBR (“January”))
    • 200;
    • ELSE
    • 100;
    • ENDIF

This structure can include various conditions:

  • Budget(
    • IF (@ISMBR (“January”))
    • 200;
    • ELSEIF (@ISMBR (“February”))
    • 300;
    • ELSEIF (@ISMBR (“March”))
    • 400;
    • ELSE
    • 0;
    • ENDIF
  • )

How does it work?

  • First, it is verified if the IF condition is met and if so, the first action is executed.
  • If it is not met, the following ELSEIF condition is analyzed and if it is met, the action listed here is executed; and so on: if the ELSEIF conditions are not met, the following are analyzed and the one that is met leads to the action that is associated with it.
  • If none of the conditions are met, then the action contained in the ELSE clause is applied.

IF structures can also be included within other IF structures; each of them must end with its corresponding ENDIF.

  • Budget(
    • IF (@ISMBR (“January”))
      • IF (Sales> = 200)
        • IF (@ISMBR (“Germany”))
          • 200;
        • ELSE
          • 100;
        • ENDIF
      • ELSE
        • 250;
      • ENDIF
    • ELSE
      • IF (Sales> = 300)
        • 400;
      • ELSE
        • 350;
      • ENDIF
    • ENDIF
  • )

This structure includes the following conditions:

  • If the month is “January”, the sales are equal to or greater than 200 and the market is Germany: budget = 200.
  • If the month is “January”, the sales are equal to or greater than 200 and the market is NOT Germany: budget = 100.
  • If the month is «January» and sales are less than 200: budget = 250.
  • If the month is not «January» and the sales are equal to or greater than 300: budget = 400.
  • If the month is not «January» and the sales are less than 300: budget = 350.

The same condition can involve several actions:

Example:

  • Budget(
    • IF (@ISMBR (“YEAR 2020”))
      • Europe = 100;
      • America = 200;
      • Asia = 300;
    • ELSE
      • 0:
    • ENDIF
  • )

These formulas are calculated simultaneously, not sequentially. This must be taken into account, since in some cases the result may be different from what we expect.

Example: We assume that «America» ​​has a target of 100; we want that of Europe to be equal to this and then we want to increase that of «America» ​​to 200:

  • Budget (
    • IF (@ISMBR (“YEAR 2020”))
      • Europe = America;
      • America = 200;
    • ELSE
      • 0:
    • ENDIF
  • )

As the formulas are executed simultaneously, the same objective is applied to «Europe» and to «America», 200 (it is not applied to «Europe» the one that «America» had at the beginning: 100).

III. Conditions

The condition can be defined by operators:

  • < (minor)
  • > (major)
  • <= (minor than or equal)
  • > = (major than or equal)
  • == (equal)
  • <> or! = (different)

For example:

  • Budget(
    • IF («Sales»> = 100)
    • 200;
    • ELSE
    • 100;
    • ENDIF
  • )

Boolean functions can also be included; some examples:

  • @ISUDA
  • @ISMBR
  • @ISLEV
  • @ISGEN
  • @ISPARENT
  • @ISCHILD

Attributes can also be used with the commands:

  • @ATTRIBUTE
  • @WITHATTR

And it can be used with UDA.

Within the conditions you can include two or more conditions joined by AND / OR.

a) IF («Condition A» AND «Condition B»): Both conditions must be met.

Example:

  • Budget(
    • IF (@ISMBR («January») AND «Sales»> = 100)
    • 200;
    • ELSE
    • 100;
    • ENDIF
  • )

b) IF (“Condition A” OR “Condition B”): It is enough that one of the two conditions is met.

Example:

  • Budget(
    • IF (@ISMBR (“January”) OR “Sales”> = 100)
    • 200;
    • ELSE
    • 100;
    • ENDIF
  • )

The negative condition «NOT» can also be used:

  • IF (NOT “Condition A”): If the condition is not met, the action is performed

Example:

  • Budget(
    • IF (NOT @ISMBR (“January”))
    • 200;
    • ELSE
    • 100;
    • ENDIF
  • )

If the month is not January, the budget is 200, otherwise (that is, if the month is January), the goal is 100.

IV. Order of conditions

For efficiency, when we have several conditions it is preferable to order them starting with those conditions that meet more members:

For example: the following structure:

  • Budget(
    • IF (NOT @ISMBR (“January”))
    • 200;
    • ELSE
    • 100;
    • ENDIF
  • )

It is more efficient than:

  • Budget(
    • IF (@ISMBR (“January”))
    • 100;
    • ELSE
    • 200;
    • ENDIF
  • )

In the first structure 11 months meet the first condition and only 1 month meets the second, while in the second structure it is just the opposite.

But you have to be careful that there is not a dependency problem:

  • With the IF … ELSEIF structure a dependency problem can occur when the value of one member depends on the value of another member; in this case those independent members must be placed in previous conditions to those members that are dependent (their values ​​depend on the value of members that should have been previously calculated).

Example: The following structure is correct

  • Budget(
    • IF (@ISMBR (“January”))
    • 100;
    • IF (@ISMBR (“February”))
    • «January» + 100;
    • IF (@ISMBR (“March”))
    • «February» + 100;
    • IF (@ISMBR (“April”))
    • «March» + 100;
    • ELSE
    • 0;
    • ENDIF
  • )

Instead the following structure is incorrect:

  • Budget (
    • IF (@ISMBR (“April”))
    • «March» + 100;
    • IF (@ISMBR (“March”))
    • «February» + 100;
    • IF (@ISMBR (“February”))
    • «January» + 100;
    • IF (@ISMBR (“January”))
    • 100;
    • ELSE
    • 0;
    • ENDIF
  • )

If it is calculated using the block calculation system, the calculation is incorrect: Essbase calculates condition by condition. First calculate the following block:

  • IF (@ISMBR (“April”))
  • «March» + 100;

Since “March” has not yet been calculated, its value is 0, so April is 100 (0 + 100); wrong result.

V. IF vs FIX

As a general rule, it is often stated that the FIX structure should be used with members of sparse dimensions and the IF structure with members of dense dimensions.

While with sparse dimensions this statement is valid:

  • The reason is that when using FIX with sparse dimensions, the number of blocks on which an action is performed is limited, which does not happen if IF is used.

With dense dimensions this statement must be qualified:

a) If we apply a single logic to the entire selection, both FIX and IF can be used.

Suppose the dimension «Months» is dense: the following two structures are valid:

FIX structure:

  • FIX (@DESCENDANTS (“Months”))
  • Budget = 100;
  • ENDFIX

IF structure:

  • Budget(
  • IF (@ISMBR (@DESCENDANTS (“Months”))
  • 100;
  • ENDIF
  • )

b) If we apply different logics, it may be more efficient to apply the IF structure:

The following IF structure opens a block and while the block is in memory it applies the different logics (avoid opening and closing the same block several times).

  • Budget(
    • IF (@ISMBR (“January”))
    • 100;
    • ELSEIF (@ISMBR (“February”))
    • 200;
    • ELSEIF (@ISMBR (“March”))
    • 300;
    • ELSEIF (@ISMBR (“April”))
    • 400;
    • ENDIF
  • )

The previous structure is more efficient than the following FIX structure: in this case Essbase opens and closes the same block several times.

  • FIX (@DESCENDANTS (“January”))
  • Budget = 100;
  • ENDFIX
  • FIX (@DESCENDANTS (“February”))
  • Budget = 200;
  • ENDFIX
  • FIX (@DESCENDANTS (“March”))
  • Budget = 300;
  • ENDFIX
  • FIX (@DESCENDANTS (“April”))
  • Budget = 400;
  • ENDFIX

c) But if it is a complex condition, a FIX structure may be more efficient:

For example: suppose the dimensions «Months», «Years» and «Products» are dense.

The following FIX structure:

  • FIX («Year 2020», «Product» A «)
    • FIX (@DESCENDANTS (“January”))
    • Budget = 100;
    • ENDFIX
    • FIX (@DESCENDANTS (“February”))
    • Budget = 200;
    • ENDFIX
    • FIX (@DESCENDANTS (“March”))
    • Budget = 300;
    • ENDFIX
    • FIX (@DESCENDANTS (“April”))
    • Budget = 400;
    • ENDFIX
  • ENDFIX

It can be more efficient than:

  • Budget (
    • IF (@ISMBR (“January”) AND @ISMBR (“Year 2020”) AND (“Product“ A ”))
    • 100;
    • ELSEIF (@ISMBR (“February”) AND @ISMBR (“Year 2020”) AND (“Product“ A ”))
    • 200;
    • ELSEIF (@ISMBR (“March”) AND @ISMBR (“Year 2020”) AND (“Product“ A ”))
    • 300;
    • ELSEIF (@ISMBR (“April”) AND @ISMBR (“Year 2020”) AND (“Product“ A ”))
    • 400;
    • ENDIF
  • )

Time would have to be measured.

d) IF can also be very slow if the logic is applied to many blocks; it might be more efficient to use a FIX structure.

  • As in the previous case, it would be necessary to measure the times.

While an IF structure can be included within a FIX structure, a FIX structure cannot be included within an IF structure.

  • FIX (“Year 2021”, Germany)
    • Budget (
      • IF (@ISMBR (“January”))
      • 200;
      • ELSE
      • 100;
      • ENDIF
    • )
  • ENDFIX

The DATACOPY command cannot be included within an IF structure, but it can be included within a FIX structure.

We saw earlier that IF can be included in a formula associated with an outline member, whereas FIX cannot be used in this case.

Español

I. Introducción

IF_ELSEIF es una estructura condicional: si se cumple la condición se realiza una acción; si no se cumple se realiza otra acción.

  • Presupuesto(
    • IF(@ISMBR(“Enero”))
    • 200;
    • ELSE
    • 100;
    • ENDIF
  • )

Si el miembro que se está calculando es “enero” el presupuesto es 200; si no lo es el presupuesto es 100.

II. Estructura

Su estructura comienza por IF y finaliza por ENDIF.

  • Cada condición va incluida entre paréntesis.
  • Cada acción finaliza con “;”

Esta estructura se puede incluir en un script de cálculo o en una fórmula asociada a un miembro del outline.

  • Si se utiliza en un script toda la estructura va incluida entre paréntesis y asociada a un miembro del outline (en el ejemplo anterior “Presupuesto”). También se podría utilizar para abrir la estructura otro miembro de la misma dimensión. Por ejemplo:
    • Ventas(
      • IF(@ISMBR(“Enero”))
      • Presupuesto = 200;
      • ELSE
      • Presupuesto = 100;
      • ENDIF
    • )
  • En una fórmula asociada a un miembro del outline no hay que incluirla entre paréntesis, ni iniciarla indicando ese miembro del outline. Por ejemplo, en el caso anterior podríamos asociar esta fórmula al miembro del outline “Presupuesto”; la estructura sería:
    • IF(@ISMBR(“Enero”))
    • 200;
    • ELSE
    • 100;
    • ENDIF

Esta estructura puede incluir diversas condiciones:

  • Presupuesto(
  • IF(@ISMBR(“Enero”))
  • 200;
  • ELSEIF(@ISMBR(“Febrero”))
  • 300;
  • ELSEIF(@ISMBR(“Marzo”))
  • 400;
  • ELSE
  • 0;
  • ENDIF
  • )

¿Cómo funciona?

  • Primero se verifica si se cumple la condición IF y si es así se ejecuta la primera acción.
  • Si no se cumple se analiza la siguiente condición ELSEIF y si se cumple se ejecuta la acción aquí recogida; así sucesivamente: si no se van cumpliendo las condiciones ELSEIF se van analizando los siguientes y aquella que se cumpla conlleva que se realice la acción que lleva asociada.
  • Si no se cumple ninguna de las condiciones entonces se aplica la acción recogida en la cláusula ELSE.

También se pueden incluir estructuras IF dentro de otras estructuras IF; cada una de ellas debe finalizar con su correspondiente ENDIF.

  • Presupuesto(
    • IF(@ISMBR(“Enero”))
      • IF(Ventas >= 200)
        • IF (@ISMBR(“Alemania”))
          • 200;
        • ELSE
          • 100;
        • ENDIF
      • ELSE
        • 250;
      • ENDIF
    • ELSE
      • IF(Ventas >= 300)
        • 400;
      • ELSE
        • 350;
      • ENDIF
    • ENDIF
  • )

Esta estructura incluye las siguientes condiciones:

  • Si el mes es “Enero”, las ventas son iguales o superiores a 200 y el mercado es Alemania: presupuesto = 200.
  • Si el mes es “Enero”, las ventas son iguales o superiores a 200 y el mercado NO es Alemania: presupuesto = 100.
  • Si el mes es “Enero” y las ventas son inferiores a 200: presupuesto = 250.
  • Si el mes No es “Enero” y las ventas son iguales o superiores a 300: presupuesto = 400.
  • Si el mes No es “Enero” y las ventas son inferiores a 300: presupuesto = 350.

Una misma condición puede llevar aparejadas varias acciones:

Ejemplo:

  • Presupuesto(
    • IF(@ISMBR(“AÑO 2020”))
      • Europa = 100;
      • América = 200;
      • Asia = 300;
    • ELSE
      • 0:
    • ENDIF
  • )

Estas fórmulas se calculan de forma simultánea, no de forma secuencial. Esto hay que tenerlo en cuenta, ya que en algunos casos el resultado puede ser diferente al que esperamos.

Ejemplo: Partimos de que “América” tiene un objetivo de 100; queremos que el de Europa sea igual a este y a continuación queremos incrementar el de “América” a 200:

  • Presupuesto (
    • IF(@ISMBR(“AÑO 2020”))
      • Europa = América;
      • América = 200;
    • ELSE
      • 0:
    • ENDIF
  • )

Como las fórmulas se ejecutan simultáneamente, a “Europa” se le aplica el mismo objetivo que a “América”, 200, no el que tenía ésta al principio (100).

III. Condiciones

La condición se puede definir mediante operadores:

  • < (menor)
  • > (mayor)
  • <= (menor o igual)
  • >= (mayor o igual)
  • == (igual)
  • <> o != (distinto de)

Por ejemplo:

  • Presupuesto(
    • IF(“Ventas” >= 100)
    • 200;
    • ELSE
    • 100;
    • ENDIF
  • )

También se pueden incluir funciones booleanas; algunos ejemplos:

  • @ISUDA
  • @ISMBR
  • @ISLEV
  • @ISGEN
  • @ISPARENT
  • @ISCHILD

También se pueden utilizar atributos utilizando los comandos:

  • @ATTRIBUTE
  • @WITHATTR

Y se puede utilizar con UDA.

Dentro de las condiciones se puede incluir dos o más condiciones unidas por AND / OR.

a) IF(“Condición A” AND “Condición B”): Se tienen que cumplir las dos condiciones.

Ejemplo:

  • Presupuesto(
    • IF(@ISMBR(“Enero”) AND “Ventas” >= 100)
    • 200;
    • ELSE
    • 100;
    • ENDIF
  • )

b) IF(“Condición A” OR “Condición B”): Basta con que se cumpla una de las dos condiciones.

Ejemplo:

  • Presupuesto(
    • IF(@ISMBR(“Enero”) OR “Ventas” >= 100)
    • 200;
    • ELSE
    • 100;
    • ENDIF
  • )

También se puede utilizar la condición negativa “NOT”.:

  • IF(NOT “Condición A”): Si no se cumple la condición se realiza la acción

Ejemplo:

  • Presupuesto(
    • IF(NOT @ISMBR(“Enero”))
    • 200;
    • ELSE
    • 100;
    • ENDIF
  • )

Si el mes no es enero el objetivo es 200, en caso contrario (es decir, si el mes sí es enero), el objetivo es 100.

IV. Orden de las condiciones

Por eficiencia, cuando tengamos varias condiciones es preferible ordenarlas empezando por aquellas condiciones que cumplan más miembros:

Por ejemplo: la siguiente estructura:

  • Presupuesto(
    • IF(NOT @ISMBR(“Enero”))
    • 200;
    • ELSE
    • 100;
    • ENDIF
  • )

Es más eficiente que:

  • Presupuesto(
    • IF(@ISMBR(“Enero”))
    • 100;
    • ELSE
    • 200;
    • ENDIF
  • )

En la primera estructura 11 meses cumplen la primera condición y tan sólo 1 mes cumple la segunda, mientras que en la segunda estructura es justo al contrario.

Pero hay que tener cuidado que no haya un problema de dependencia:

  • Con la estructura IF … ELSEIF se puede producir un problema de dependencia cuando el valor de un miembro depende del valor de otro miembro; en este caso hay que tener cuidado de situar aquellos miembros independientes en condiciones anteriores a aquellos miembros que sean dependientes (sus valores dependan del valor de miembros que se han debido calcular previamente).

Ejemplo: La siguiente estructura es correcta

  • Presupuesto(
    • IF(@ISMBR(“Enero”))
    • 100;
    • IF(@ISMBR(“Febrero”))
    • “Enero” + 100;
    • IF(@ISMBR(“Marzo”))
    • “Febrero” + 100;
    • IF(@ISMBR(“Abril”))
    • “Marzo” + 100;
    • ELSE
    • 0;
    • ENDIF
  • )

En cambio la siguiente estructura es incorrecta:

  • Presupuesto (
    • IF(@ISMBR(“Abril”))
    • “Marzo” + 100;
    • IF(@ISMBR(“Marzo”))
    • “Febrero” + 100;
    • IF(@ISMBR(“Febrero”))
    • “Enero” + 100;
    • IF(@ISMBR(“Enero”))
    • 100;
    • ELSE
    • 0;
    • ENDIF
  • )

Si se calcula aplicando el sistema de cálculo por bloque el cálculo es incorrecto: Essbase va calculando condición por condición. Primero calcula el siguiente bloque:

  • IF(@ISMBR(“Abril”))
  • “Marzo” + 100;

Como “Marzo” aún no se ha calculado su valor es 0, por lo que Abril es 100 (0 + 100); resultado incorrecto.

V. IF vs FIX

Cómo regla general se suele afirmar que hay que utilizar la estructura FIX con miembros de dimensiones dispersas y la estructura IF con miembros de dimensiones densas.

Mientras que con dimensiones dispersas esta afirmación es válida:

  • El motivo es que al utilizar FIX con dimensiones dispersas se limita el número de bloques sobre lo que se realiza una acción, lo que no ocurre si se utiliza IF.

Con dimensiones densas esta afirmación hay que matizarla:

a) Si aplicamos una única lógica a toda la selección se puede utilizar tanto FIX como IF.

Supongamos que la dimensión “Meses” es densa: las dos estructuras siguientes son válidas:

Estructura FIX:

  • FIX(@DESCENDANTS(“Meses”))
  • Presupuesto = 100;
  • ENDFIX

Estructura IF:

  • Presupuesto(
  • IF(@ISMBR(@DESCENDANTS(“Meses”))
  • 100;
  • ENDIF
  • )

b) Si aplicamos distintas lógicas puede resultar más eficiente aplicar la estructura IF:

La siguiente estructura IF abre un bloque y mientras el bloque está en memoria va aplicando las distintas lógicas (evita abrir y cerrar el mismo bloque varias veces).

  • Presupuesto(
    • IF(@ISMBR(“Enero”))
    • 100;
    • ELSEIF(@ISMBR(“Febrero”))
    • 200;
    • ELSEIF(@ISMBR(“Marzo”))
    • 300;
    • ELSEIF(@ISMBR(“Abril”))
    • 400;
    • ENDIF
  • )

La estructura anterior es más eficiente que la siguiente estructura FIX: en este caso Essbase va abriendo y cerrando el mismo bloque varias veces.

  • FIX(@DESCENDANTS(“Enero”))
  • Presupuesto = 100;
  • ENDFIX
  • FIX(@DESCENDANTS(“Febrero”))
  • Presupuesto = 200;
  • ENDFIX
  • FIX(@DESCENDANTS(“Marzo”))
  • Presupuesto = 300;
  • ENDFIX
  • FIX(@DESCENDANTS(“Abril”))
  • Presupuesto = 400;
  • ENDFIX

c) Pero si se trata de una condición compleja puede ser más eficiente una estructura FIX:

Por ejemplo: supongamos que las dimensiones “Meses”, “Años” y “Productos” son densas.

La siguiente estructura FIX:

  • FIX(“Año 2020”, “Producto “A”)
    • FIX(@DESCENDANTS(“Enero”))
    • Presupuesto = 100;
    • ENDFIX
    • FIX(@DESCENDANTS(“Febrero”))
    • Presupuesto = 200;
    • ENDFIX
    • FIX(@DESCENDANTS(“Marzo”))
    • Presupuesto = 300;
    • ENDFIX
    • FIX(@DESCENDANTS(“Abril”))
    • Presupuesto = 400;
    • ENDFIX
  • ENDFIX

Puede resultar más eficiente que:

  • Presupuesto (
    • IF(@ISMBR(“Enero”) AND @ISMBR(“Año 2020”) AND (“Producto “A”))
    • 100;
    • ELSEIF(@ISMBR(“Febrero”) AND @ISMBR(“Año 2020”) AND (“Producto “A”))
    • 200;
    • ELSEIF(@ISMBR(“Marzo”) AND @ISMBR(“Año 2020”) AND (“Producto “A”))
    • 300;
    • ELSEIF(@ISMBR(“Abril”) AND @ISMBR(“Año 2020”) AND (“Producto “A”))
    • 400;
    • ENDIF
  • )

Habría que medir los tiempos.

d) También IF puede ser muy lento si la lógica se aplica a muchos bloques; podría resultar más eficiente utilizar una estructura FIX.

  • Al igual que en el caso anterior, habría que medir los tiempos.

Mientras que una estructura IF se puede incluir dentro de una estructura FIX, en cambio una estructura FIX no se puede incluir dentro de una estructura IF.

  • FIX(“Año 2021”, Alemania)
    • Presupuesto(
      • IF(@ISMBR(“Enero”))
      • 200;
      • ELSE
      • 100;
      • ENDIF
    • )
  • ENDFIX

El comando DATACOPY no se puede incluir dentro de una estructura IF, pero sí dentro de una estructura FIX.

Vimos antes que IF se puede incluir en una fórmula asociada a un miembro del outline, en cambio FIX no se puede utilizar en este caso.

Anuncio publicitario