Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
j_nlucas
Partner - Contributor III
Partner - Contributor III

Mode function not working

Hi,

I need to calculate the MODE of the result of the following expression: 

 

if(MaxString(_CodTipoSeleccion) = 'EF',
((Sum({<_KeyFecha={'>=$(v_FechaInicioSK)<=$(v_FechaFinSK)'},Año,Fecha,Día,DiaMes,Semana,Mes,MesNum,nMes,Trimestre, FchDocumentoVenta= >}MargenBruto) - Sum({<_KeyFecha={'>=$(v_FechaInicioSK)<=$(v_FechaFinSK)'},Año,Fecha,Día,DiaMes,Semana,Mes,MesNum,nMes,Trimestre, FchDocumentoVenta= >}ImpGastos)) / (Sum({<_KeyFecha={'>=$(v_FechaInicioSK)<=$(v_FechaFinSK)'},Año,Fecha,Día,DiaMes,Semana,Mes,MesNum,nMes,Trimestre, FchDocumentoVenta= >}ImporteVenta)- Sum({<_KeyFecha={'>=$(v_FechaInicioSK)<=$(v_FechaFinSK)'},Año,Fecha,Día,DiaMes,Semana,Mes,MesNum,nMes,Trimestre, FchDocumentoVenta= >}ImpGastos)))
,
((Sum(MargenBruto)- sum(ImpGastos)) / (Sum(ImporteVenta)-sum(ImpGastos)))
)

 

I wrapped all that into a variable that I've used in the Mode function but I keep getting nulls. 

 

I'm using it in a straight table with three dimensions. 

 

Any idea? 

 

Thank you

Labels (1)
  • mode

1 Solution

Accepted Solutions
jfkinspari
Partner - Specialist
Partner - Specialist

try using RangeMode(Sum(MargenBruto))

View solution in original post

10 Replies
jfkinspari
Partner - Specialist
Partner - Specialist

Perhaps you have included a "=" and are calculating the variable before it's input into the straight table
j_nlucas
Partner - Contributor III
Partner - Contributor III
Author

Hi Jfkinspari, no equal included. 

jfkinspari
Partner - Specialist
Partner - Specialist

Do you get a result if you use any other aggregation function, e.g. count?
j_nlucas
Partner - Contributor III
Partner - Contributor III
Author

No I don't

jfkinspari
Partner - Specialist
Partner - Specialist

Okay, then I suggest you backtrack the problem, by moving the expression from the variable into the table itself, and find out when it starts to fails
j_nlucas
Partner - Contributor III
Partner - Contributor III
Author

The expression works well with and without the variable in the table.

The problem arises when I apply an aggregation function to it. I am not sure I to backtrack that from there... 

j_nlucas
Partner - Contributor III
Partner - Contributor III
Author

I have now reduced the expression to this:

Mode(Sum(MargenBruto))

and it's still returning null values

 

 

jfkinspari
Partner - Specialist
Partner - Specialist

try using RangeMode(Sum(MargenBruto))
j_nlucas
Partner - Contributor III
Partner - Contributor III
Author

That works!!

Thank you so much for your help. It's really appreciated!