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

Calculo en base al mes anterior

Hola a todos! Estoy utilizando la sig. expresion para calcular las ventas en base al mes anterior, y utilizo la funcion Max(), porque pueden el usuario seleccionar varios meses, y tengo que tener en cuenta solo el ultimo mes. Pero nose porque no me toma esa funcion. Alguna otra opcion?

Sum( {$<MesNro={$(=Max(MesNro)-1)}>}VENTA)

Gracias.

Saludos

1 Solution

Accepted Solutions
Nicole-Smith

Sum( {$<MesNro={'$(=num(Max(MesNro)-1, '00'))'}>}VENTA)

You should use a date field instead of just a month because if your max month is January, you're going to get 0 for the month since you're subtracting 1.

View solution in original post

6 Replies
Nicole-Smith

What does MesNro look like?  If it's a date, you may need to format it as such.  You probably also need single quote to denote that it is a string.

Sum( {$<MesNro={'$(=Max(MesNro)-1)'}>}VENTA)

or

Sum( {$<MesNro={'$(=date(Max(MesNro)-1))'}>}VENTA)

Not applicable
Author

Hi everyone! I am using this expression to calculate sales based on the previous month, and I use  Max() function, because the user can select several months, and I have to take the previous month of the last month selected.

But do not know why I do not take the funcion Max(). Any other option?

Sum ({$ <MesNro={$(=Max(MesNro)-1)}>} VENTA)

Thank you.

Not applicable
Author

This MesNro is the number of the Month. (01, 02, 03 etc)

Nicole-Smith

Sum( {$<MesNro={'$(=num(Max(MesNro)-1, '00'))'}>}VENTA)

You should use a date field instead of just a month because if your max month is January, you're going to get 0 for the month since you're subtracting 1.

sebastiandperei
Specialist
Specialist

Ponelo en un gráfico de tabla, por ejemplo, pivotante.

No le pongas título a la expresión. Además, agregá una seguna expresión con un valor, por ejemplo, 1.

Si comprendí bien, esa expresión no te da valores. Bien, ahora en el título de la expresión te va a aparecer la expresión, peeeero, te va a reemplazar el $(=Max(MesNro)-1) por el valor que te está dando.

Considerando que estamos en Enero, es posible que eso te de Cero, por lo cual, no hay mes cero.

Lo que deberías probar sería:

sum ({<fecha={">=$(=MonthStart(Addmonths(Max(fecha),-1)))

                       <=$(=MonthEnd(Addmonths(Max(fecha),-1)))

"}>} VENTA)

Not applicable
Author

Muchas gracias. Saludos!