Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
astuckrath
Contributor II
Contributor II

Let and IF and ElseIF

Hola, tengo un problema con la lógica de variables y cómo hacer recargas según su valoración, en el ejemplo siguiente se cumple la condición de Sum(fabs(Factor_Distrib_CAAP)) es igual a 1 por lo tanto la carga debe cumplirse en el primer IF.

 

Hi, I work in QS and i have to do something like this, but if vDistrib_CAAP = 1 this doesnt work like i want

 

Let vDistrib_CAAP = 'Sum(fabs(Factor_Distrib_CAAP))';  //This example this is 1

Let vDistrib_Margen = 'Sum(fabs(Factor_Distrib_Margen))';

 

IF '$(vDistrib_CAAP)=1' then

LOAD
Mercado_Distrib_CAAP as Mercado_Distrib,
"Factor_Distrib_CAAP" as Factor_Distrib
Resident Distribucion_CAAP;

ElseIF '$(vDistrib_Margen)=1' then
LOAD
Mercado_Distrib_Margen as Mercado_Distrib,
"Factor_Distrib_Margen" as Factor_Distrib
Resident Distribucion_Margen;

Else

LOAD
Mercado_Distrib_CLP as Mercado_Distrib,
"Factor_Distrib_CLP" as Factor_Distrib
Resident Distribucion_CLP;

Labels (1)
1 Solution

Accepted Solutions
sunny_talwar

Sorry, I totally missed your response. You are doing a sum in your load

image.png

Yet you need another sum before you save it to the variable?

image.png

Is that correct? If it is, then try this may be

Distribucion_CAAP:
NoConcatenate
LOAD Sum(fabs(Factor_Distrib_CAAP)) as Factor_Distrib_CAAP;
LOAD Mercado as Mercado_Distrib_CAAP,
     Sum(Valor_Distrib/Valor_Distrib_Total) as Factor_Distrib_CAAP
Resident Distribucion_CAAP_1
Group by Mercado;

LET vDistrib_CAAP = Peek('Factor_Distrib_CAAP');

View solution in original post

7 Replies
sunny_talwar

Where is Factor_Distrib_CAAP coming from? A table loaded before you use this in Let statement?

astuckrath
Contributor II
Contributor II
Author

Yes:

Distribucion_CAAP:
NoConcatenate
LOAD Mercado as Mercado_Distrib_CAAP,
Sum(Valor_Distrib/Valor_Distrib_Total) as Factor_Distrib_CAAP
Resident Distribucion_CAAP_1
Group by Mercado;

Let vDistrib_CAAP = 'Sum(fabs(Factor_Distrib_CAAP))';

Distribucion_Margen:
NoConcatenate
LOAD Mercado as Mercado_Distrib_Margen,
Sum(Valor_Distrib/Valor_Distrib_Total) as Factor_Distrib_Margen

Let vDistrib_Margen = 'Sum(fabs(Factor_Distrib_Margen))';

astuckrath
Contributor II
Contributor II
Author

Someone?

sunny_talwar

Sorry, I totally missed your response. You are doing a sum in your load

image.png

Yet you need another sum before you save it to the variable?

image.png

Is that correct? If it is, then try this may be

Distribucion_CAAP:
NoConcatenate
LOAD Sum(fabs(Factor_Distrib_CAAP)) as Factor_Distrib_CAAP;
LOAD Mercado as Mercado_Distrib_CAAP,
     Sum(Valor_Distrib/Valor_Distrib_Total) as Factor_Distrib_CAAP
Resident Distribucion_CAAP_1
Group by Mercado;

LET vDistrib_CAAP = Peek('Factor_Distrib_CAAP');
astuckrath
Contributor II
Contributor II
Author

Thanks, but i need to sum the absolute value because if there's a negative number the sum it's going to be > 1, that's the reason for that formula

sunny_talwar

image.png

astuckrath
Contributor II
Contributor II
Author

tranks you a lot

 

the change i did was:

 

Distribucion_CAAP:
NoConcatenate
LOAD Mercado as Mercado_Distrib_CAAP,
Sum(Valor_Distrib/Valor_Distrib_Total) as Factor_Distrib_CAAP
Resident Distribucion_CAAP_1
Group by Mercado;


LOAD SUM(fabs(Factor_Distrib_CAAP)) as Valida_Distrib_CAAP Resident Distribucion_CAAP; //THIS

Let vDistrib_CAAP = Peek('Valida_Distrib_CAAP'); //THIS


Distribucion_Margen:
NoConcatenate
LOAD Mercado as Mercado_Distrib_Margen,
Sum(Valor_Distrib/Valor_Distrib_Total) as Factor_Distrib_Margen
Resident Distribucion_Margen_1 Group by Mercado;


LOAD SUM(fabs(Factor_Distrib_Margen)) as Valida_Distrib_Margen Resident Distribucion_Margen;

Let vDistrib_Margen = Peek('Valida_Distrib_Margen');

 

and whit PEEK function I have the number that i need to the IF and ELSEIF Cycle.