Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
raulvazquez7
Contributor
Contributor

Aggr con Set Analysis / Aggr with set analysis

Muy buenas a todos me gustaría que me ayudaseis con esta fórmula que heredo.

Es una expresión de gráfico con condicional, cuando //hay seleccionado , es decir, cuando se cumple la condición quiero que me devuelva los litros el mes del año anterior por [EA.id] único según el filtro seleccionado (es decir, si escojo en el filtro Mayo 2019 quiero que me devuelva Mayo 2018 y cuando // no hay seleccionado , es decir, cuando no se cumple la condición quiero que me devuelva la suma de litros por [EA.id] único del mes del año anterior al actual (es decir si actualmente estamos en Junio de 2019, quiero que me devuelva Junio de 2018) esta última condición me funciona y me devuelve el valor esperado, el problema viene con //hay seleccionado que me devuelve 0 como valor. 

A continuación expongo las dos fórmulas, como veréis //no hay seleccionado me devuelve el valor esperado.

//

Hello! I would like you to help me with this expression.

It is an expression of conditional graph, when // is selected, that is, when the condition is met I want to return the liters the month of the previous year by [EA.id] unique according to the selected filter (that is, if I choose in the filter May 2019 I want you to return May 2018 and when // is not selected, that is, when the condition is not met I want you to return the sum of liters for [EA.id] unique to the month of the year before the current one (ie if we are in June 2019, I want to return June 2018) this last condition works for me and returns the expected value, the problem comes with // there is selected that returns 0 as a value.

Then I expose the two formulas, as you will see // there is no selected me the expected value returns.

Expresión 1:

if ( (GetSelectedCount([Año])>=1) AND (GetSelectedCount([Nombre Mes])>=1),
//hay seleccionado
sum(aggr(sum({$<[Mes]=,[monthorig]=,[Nombre Mes]=,[Año]={$(=SubField(GetFieldSelections([Año],',',12),',',GetSelectedCount([Año]))),$(=SubField(GetFieldSelections([Año],',',12),',',GetSelectedCount([Año]))-1)},[Número Mes]={$(=match(SubField(GetFieldSelections([Nombre Mes],',',12),',',GetSelectedCount([Nombre Mes])),'Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'))}>}distinct Litros), [EA.id]))
,
//no hay seleccionado
sum({$<[Mes]=,[monthorig]=,[Nombre Mes]=,[Año]={$(=Year(DATE(TODAY()-1))),$(=Year(DATE(TODAY()-1))-1)},[Número Mes]={$(=num(Month(DATE(TODAY()-1))))}>}aggr(sum( distinct Litros), [EA.id]))
)

Expresión 2:

if ( (GetSelectedCount([Año])>=1) AND (GetSelectedCount([Nombre Mes])>=1),
//hay seleccionado
sum({$<[Mes]=,[monthorig]=,[Nombre Mes]=,[Año]={$(=SubField(GetFieldSelections([Año],',',12),',',GetSelectedCount([Año]))),$(=SubField(GetFieldSelections([Año],',',12),',',GetSelectedCount([Año]))-1)},[Número Mes]={$(=match(SubField(GetFieldSelections([Nombre Mes],',',12),',',GetSelectedCount([Nombre Mes])),'Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'))}>}aggr(sum(distinct Litros), [EA.id]))
,
//no hay seleccionado
sum({$<[Mes]=,[monthorig]=,[Nombre Mes]=,[Año]={$(=Year(DATE(TODAY()-1))),$(=Year(DATE(TODAY()-1))-1)},[Número Mes]={$(=num(Month(DATE(TODAY()-1))))}>}aggr(sum(distinct Litros), [EA.id]))
)

Gracias y espero haber sido claro!

0 Replies