CONDITIONAL FUNCTIONS / FUNCIONES CONDICIONALES

English (Español a continuación)

The following functions can be used in formulas on outline members of dynamic dimensions.

They are conditional type structures:

  • If a certain condition is met, it returns a result, otherwise it returns another.

A.- CASE

Its structure:

  • CASE
    • When Condition 1 then Result 1
    • When Condition 2 then Result 2
    • When Condition n then Result n
    • [Else Result z]
  • END

His reading is as follows:

  • If Condition 1 is met, it returns Result 1.
  • If Condition 2 is met, it returns Result 2.
  • If Condition n is met, it returns Result n.
  • If none of the above conditions is met, it returns the result z.

The conditions are executed sequentially:

  • If it meets the 1st condition the result 1 is assigned and this structure ends.
  • Otherwise, the 2nd condition is evaluated and if it is fulfilled the result 2 is assigned and this structure ends.
  • And so on.

The “Else” clause is optional:

  • If included, it is used to assign a specific result in those cases in which none of the established conditions are fulfilled.
  • If not included, the null value is assigned to those cases in which none of the established conditions are fulfilled.

Let’s see some examples: suppose the dynamic dimension “Indicators”:

a) We include in the member “Target_Sales” of this dimension the following formula to calculate its value based on the “Sales” of the year:

  • CASE
    • When [Sales] < 100 THEN [Sales] * 2.5
    • When [Sales] < 200 THEN [Sales] * 2.0
    • When [Sales] < 300 THEN [Sales] * 1.5
    • When [Sales] < 400 THEN [Sales] * 1.2
    • Else [Sales]
  • END

b) We include in the member “Sales_Accumulated” of this dimension the following formula to calculate its value as the sum of the sales of each month:

  • CASE
    • When IS([Month].currentMember, [January]) THEN
    • Aggregate(CrossJoin({[Sale_Month]}, {[January]:[January]}))
    • When IS([Month].currentMember, [February]) THEN
    • Aggregate(CrossJoin({[Sale_Month]}, {[January]:[February]}))
    • When IS([Month].currentMember, [March]) THEN
    • Aggregate(CrossJoin({[Sale_Month]}, {[January]:[March]}))
    • When IS([Month].currentMember, [December]) THEN
    • Aggregate(CrossJoin({[Sale_Month]}, {[January]:[December]}))
  • END

More than one condition can be included in this function. Let’s look at an example:

c) We include in the member “Target_Sales” of this dimension the following formula to calculate its value based on the “Sales” of the year and the “Profit”:

  • CASE
    • When [Sales] < 100 AND [Profit] > 25 THEN [Sales] * 2.5
    • When [Sales] < 100 AND [Profit] < 25 THEN [Sales] * 2.3
    • When [Sales] < 200 AND [Profit] > 45 THEN [Sales] * 2.0
    • When [Sales] < 200 AND [Profit] < 45 THEN [Sales] * 1.0
    • Else [Sales]
  • END

Nested “CASE”s can be included. Let’s look at an example:

d) We include in the member “Target_Sales” of this dimension the following formula to calculate its value based on the “Sales” of the year and with a differentiated treatment to the “German” market:

  • CASE
    • When [Sales] < 100 THEN
      • CASE
        • When IS([Markets].currentMember, [Germany]) THEN [Sales] * 2.5
        • Else [Sales] * 2.4
      • END
    • When [Sales] < 200 THEN
      • CASE
        • When IS([Markets].currentMember, [Germany]) THEN [Sales] * 2.3
        • Else [Sales] * 2.2
      • END
    • Else [Sales]
  • END

B.- IIF

Its structure:

  • IIF(Condition, True -> Result 1, False -> Result 2)

If the established condition is met, it returns the result 1, otherwise it returns the result 2.

Let’s look at an example:

We set the following formula in the member “Target_2022”:

  • IIF (Sales > 200, Sales * 1.5, Sales * 1.2)

For those units whose sales have exceeded 200, their target for 2022 is set by multiplying sales by 1.5; otherwise by 1.2.

More than one condition can be included in the clause:

  • IIF ((Sales > 200 AND Profit > 100), Sales * 1.5, Sales * 1.2)

For those units whose sales have exceeded 200 and their profits have been greater than 100, their target for 2022 is set by multiplying sales by 1.5; otherwise by 1.2.

Another example:

  • IIF ((Sales > 200 AND IS([Markets].currentMember, [Germany])), Sales * 1.5, Sales * 1.2)

If sales have exceeded 200 and it is the “German” market, its target for 2022 is set by multiplying sales by 1.5; otherwise by 1.2.

Another example:

  • IIF ((Sales > 200 OR Profit > 100), Sales * 1.5, Sales * 1.2)

If sales have exceeded 200 or profit has been greater than 100, the target for 2022 is set by multiplying sales by 1.5; otherwise by 1.2.

Another example:

  • IIF ((Sales > 200 AND IS([Markets].currentMember, [Germany]) AND IS([Products].currentMember, [Printers])), Sales * 1.5, Sales * 1.2)

If sales have exceeded 200 and it is the “German” market and the “Printers” product, its target for 2022 is set by multiplying sales by 1.5; otherwise by 1.2.

IFF structures can be nested:

  • IIF (Sales > 200,
    • IIF(Profit > 100, Sales * 1.5, Sales * 1.3), Sales * 1.2)

For those units whose sales have exceeded 200:

  • If the profit has been greater than 100, the target for 2022 is set by multiplying sales by 1.5
  • If the profit has not exceeded this amount, the target for 2022 is set by multiplying sales by 1.3

For the rest of the units, its target for 2022 is set by multiplying sales by 1.2

C.- CASE & IIF

These two structures can be used in combination:

Let’s see an example: we include in the member «Target_2022» the following formula:

  • IIF(IsLeaf([Markets].currentMember),
    • CASE
      • When [Sales] < 100 THEN [Sales] * 2.5
      • When [Sales] < 200 THEN [Sales] * 2.0
      • When [Sales] < 300 THEN [Sales] * 1.5
      • When [Sales] < 400 THEN [Sales] * 1.2
      • Else [Sales] * 1.1
    • END
  • [Sales])

The “Target_2022” is established:

  • For markets that are level 0 members (IsLeaf function), it is calculated by applying the conditions included in the CASE structure.
  • For markets that are not level 0 members, it is equal to the amount of their sales.

Español

Las siguientes funciones se pueden utilizar en fórmulas en miembros del outline de dimensiones dinámicas.

Son estructuras de tipo condicional:

  • Si se cumple determinada condición devuelve un resultado, en caso contrario devuelve otro.

A.- CASE

Su estructura:

  • CASE
    • When Condición 1 then Resultado 1
    • When Condición 2 then Resultado 2
    • When Condición n then Resultado n
    • [Else Resultado z]
  • END

Su lectura es la siguiente:

  • Si se cumple la Condición 1 devuelve el Resultado 1.
  • Si se cumple la Condición 2 devuelve el Resultado 2.
  • Si se cumple la Condición n devuelve el Resultado n.
  • Si no se cumple ninguna de las condiciones anteriores devuelve el resultado z.

Las condiciones se van ejecutando secuencialmente:

  • Si cumple la 1ª condición se le asigna el resultado 1 y termina de aplicarse esta estructura.
  • En caso negativo pasa a evaluarse la 2ª condición y si se cumple se le asigna el resultado 2 y termina de aplicarse esta estructura.
  • Y así sucesivamente.

La cláusula “Else” es optativa:

  • Si se incluye sirve para asignar un resultado determinado en aquellos casos en los que no se cumpla ninguna de las condiciones establecidas.
  • Si no se incluye, a aquellos casos en los que no se cumpla ninguna de las condiciones establecidas se le asigna el valor nulo.

Veamos algunos ejemplos: supongamos la dimensión dinámica “Indicadores”:

a) Incluimos en el miembro “Obj_Ventas” de esta dimensión la siguiente fórmula para calcular su valor en función de las “Ventas” del año:

  • CASE
    • When [Ventas] < 100 THEN [Ventas] * 2.5
    • When [Ventas] < 200 THEN [Ventas] * 2.0
    • When [Ventas] < 300 THEN [Ventas] * 1.5
    • When [Ventas] < 400 THEN [Ventas] * 1.2
    • Else [Ventas]
  • END

b) Incluimos en el miembro “Ventas_Acumuladas” de esta dimensión la siguiente fórmula para calcular su valor como suma de las ventas de cada mes:

  • CASE
    • When IS([Mes].currentMember, [Enero]) THEN
    • Aggregate(CrossJoin({[Venta_Mes]}, {[Enero]:[Enero]}))
    • When IS([Mes].currentMember, [Febrero]) THEN
    • Aggregate(CrossJoin({[Venta_Mes]}, {[Enero]:[Febrero]}))
    • When IS([Mes].currentMember, [Marzo]) THEN
    • Aggregate(CrossJoin({[Venta_Mes]}, {[Enero]:[Marzo]}))
    • When IS([Mes].currentMember, [Diciembre]) THEN
    • Aggregate(CrossJoin({[Venta_Mes]}, {[Enero]:[Diciembre]}))
  • END

En esta función se pueden incluir más de una condición. Veamos un ejemplo:

c) Incluimos en el miembro “Obj_Ventas” de esta dimensión la siguiente fórmula para calcular su valor en función de las “Ventas” del año y del “Beneficio”:

  • CASE
    • When [Ventas] < 100 AND [Beneficio] > 25 THEN [Ventas] * 2.5
    • When [Ventas] < 100 AND [Beneficio] < 25 THEN [Ventas] * 2.3
    • When [Ventas] < 200 AND [Beneficio] > 45 THEN [Ventas] * 2.0
    • When [Ventas] < 200 AND [Beneficio] < 45 THEN [Ventas] * 1.0
    • Else [Ventas]
  • END

Se pueden incluir “CASE” anidados. Veamos un ejemplo:

d) Incluimos en el miembro “Obj_Ventas” de esta dimensión la siguiente fórmula para calcular su valor en función de las “Ventas” del año y con un tratamiento diferenciado del mercado “Alemán”:

  • CASE
    • When [Ventas] < 100 THEN
      • CASE
        • When IS([Mercados].currentMember, [Alemania]) THEN [Ventas] * 2.5
        • Else [Ventas] * 2.4
      • END
    • When [Ventas] < 200 THEN
      • CASE
        • When IS([Mercados].currentMember, [Alemania]) THEN [Ventas] * 2.3
        • Else [Ventas] * 2.2
      • END
    • Else [Ventas]
  • END

B.- IIF

Su estructura:

  • IIF(Condicición, Verdadero -> Resultado 1, Falso -> Resultado 2)

Si se cumple la condición establecida devuelve el resultado 1, en caso negativo devuelve el resultado 2.

Veamos un ejemplo:

Establecemos la siguiente fórmula en el miembro “Obj_2022”:

  • IIF (Ventas > 200, Ventas * 1.5, Ventas * 1.2)

Para aquellas unidades cuyas ventas hayan superado los 200 su objetivo para 2022 se fija multiplicando las ventas por 1,5; en caso contrario por 1,2.

Se puede incluir más de una condición en la cláusula:

  • IIF ((Ventas > 200 AND Beneficio > 100), Ventas * 1.5, Ventas * 1.2)

Para aquellas unidades cuyas ventas hayan superado los 200 y sus beneficios hayan sido superior a 100 su objetivo para 2022 se fija multiplicando las ventas por 1,5; en caso contrario por 1,2.

Otro ejemplo:

  • IIF ((Ventas > 200 AND IS([Mercados].currentMember, [Alemania])), Ventas * 1.5, Ventas * 1.2)

Si las ventas han superado los 200 y es el mercado “Alemán” su objetivo para 2022 se fija multiplicando las ventas por 1,5; en caso contrario por 1,2.

Otro ejemplo:

  • IIF ((Ventas > 200 OR Beneficio > 100), Ventas * 1.5, Ventas * 1.2)

Si las ventas han superado los 200 o el beneficio ha sido superior a 100, su objetivo para 2022 se fija multiplicando las ventas por 1,5; en caso contrario por 1,2.

Otro ejemplo:

  • IIF ((Ventas > 200 AND IS([Mercados].currentMember, [Alemania]) AND IS([Productos].currentMember, [Impresoras])), Ventas * 1.5, Ventas * 1.2)

Si las ventas han superado los 200 y es el mercado “Alemán” y el producto “Impresoras” su objetivo para 2022 se fija multiplicando las ventas por 1,5; en caso contrario por 1,2.

Las estructuras IFF se pueden anidar:

  • IIF (Ventas > 200,
    • IIF(Beneficio > 100, Ventas * 1.5, Ventas * 1.3), Ventas * 1.2)

Para aquellas unidades cuyas ventas hayan superado los 200:

  • Si su beneficio ha sido superior a 100 su objetivo para 2022 se fija multiplicando las ventas por 1,5
  • Si su beneficio no ha superado esta cantidad su objetivo para 2022 se fija multiplicando las ventas por 1,3

Para el resto de unidades su objetivo para 2022 se fija multiplicando las ventas por 1,2

C.- CASE & IIF

Estas dos estructuras se pueden utilizar de forma combinada:

Veamos un ejemplo: incluimos en el miembro “Obj_2022” la siguiente fórmula:

  • IIF(IsLeaf([Mercados].currentMember),
    • CASE
      • When [Ventas] < 100 THEN [Ventas] * 2.5
      • When [Ventas] < 200 THEN [Ventas] * 2.0
      • When [Ventas] < 300 THEN [Ventas] * 1.5
      • When [Ventas] < 400 THEN [Ventas] * 1.2
      • Else [Ventas] * 1.1
    • END
  • [Ventas])

El importe del “Obj_2022” se establece:

  • Para los mercados que son miembros de nivel 0 (función IsLeaf) se calcula aplicando las condiciones recogidas en la estructura CASE.
  • Para los mercados que no son miembros de nivel 0 se iguala al importe de sus ventas.
Anuncio publicitario