Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
pgalvezt
Specialist
Specialist

Last Month Help

Hi, Im trying to get the last month period. I have this but is not working.

sum({$< Año={'$(xAñoMax)'}, Mes={'$(xMesMax)'}, Period= >} Sum(If(Field1 <> 1, Total)))

Thanks.

11 Replies
shree909
Partner - Specialist II
Partner - Specialist II

try this

monthend(sum({$< Año={'$(xAñoMax)'}, Mes={'$(xMesMax)'}, Period= >} Sum(If(Field1 <> 1, Total))),-1)

i am not sure this works , can u send me a qvw file

pgalvezt
Specialist
Specialist
Author

Thanks but is not working.

Nicole-Smith

You cannot use the sum function inside of another sum function.

I would suggest something like:

=sum({$< Año={'$(xAñoMax)'}, Mes={'$(xMesMax)'}, Period=, Field1 /= {'1'} >} Total)

pgalvezt
Specialist
Specialist
Author

=sum({$< Año={'$(xAñoMax)'}, Mes={'$(xMesMax)'}, Period=, Field1 /= {'1'} >} Total)

/= Gives problem.

Nicole-Smith

You need to post a .qvw, otherwise there is no way for us to tell what is wrong.

pgalvezt
Specialist
Specialist
Author

I Attached the qvw file.

Thanks

pgalvezt
Specialist
Specialist
Author

Any Help?

sebastiandperei
Specialist
Specialist

Por los datos, supongo que hablás español (de dónde sos?)

If not, please, tell me and i will write again in english.

El '/=' no da error (si no, la expresión daría Nulo). Es un viejo problema del editor de expresiones de QV, que no reconoce /= o -=. Así como el = "selecciona" un valor en un campo, el -= o el /= selecciona todos los valores menos el indicado. A partir de ahí el editor te marca como error de sintaxis, pero en realidad está bien.

Ahora, si la expresión no da el resultado que esperás, necesito que me digas qué es lo que realmente querés calcular. Las variables xAñoMax y xMesMax efectivamente te devuelven los valores de Año y Mes máximos, pero no te olvides que éstos se modifican con las selecciones que hacés. O sea, mandaste la aplicación con 2012 seleccionado, entonces, xAñoMax=2012, y xMesMax=Julio, porque es el máximo mes que tiene datos para el 2012. Si seleccionás 2011, sería xAñoMax=2011, y xMesMax=Diciembre, por la misma razón que el anterior. El tema es que seleccionando 2011, xMesMax=Agosto. Esto es porque xMesMax debería ser:

xMesMax=Month(Date(Max(Periodo)))

Ahora, antes de seguir suponiendo, qué es lo que necesitás que te muestre?

Para saber el verdadero valor que necesitás, te sugiero que crees una tabla con la expresión sum(Deuda_Total), sin set análisis, y empezá a seleccionar los campos que necesitás fijar. Anotate el resultado y comparalo con la expresión que te pasó Nicole. Después avisame cómo te fue!

Not applicable

maybe its to late, but, in the script asign this:

/* PRIMERO EL CALENDARIO */

/* En el siguiente bloque se setean fechas min y max para el calendario a generar, pero recuerde que las fechas son un campo

comun con otras tablas de datos que se carguen, conclusión: el rango generado por el calendario no limita las fechas finalmente

mostradas por ejemplo en un listbox de CalendarDate */

LET vDateMin = Num(MakeDate(2011,01,15));    // fecha minima del calendario

LET vDateMax = Floor(MonthEnd(Today()));     // la máxima fecha será fin del mes presente

//LET vDateMax = Floor(Today());     // la máxima fecha será fin del mes presente

LET vDateToday = Num(Today());

TempCalendar:

LOAD

$(vDateMin) + RowNo() - 1 AS DateNumber,

Date($(vDateMin) + RowNo() - 1) AS TempDate

AUTOGENERATE 1

WHILE $(vDateMin)+IterNo()-1<= $(vDateMax);

Calendar:

LOAD

Date(TempDate) AS Fecha,       // solo fecha   dd/mm/yyyy

// Standard Date Objects

Day(TempDate) AS CalendarDayOfMonth,

WeekDay(TempDate) AS CalendarDayName,

Week(TempDate) AS CalendarWeekOfYear,

Month(TempDate) AS CalendarMonthName,

'Q' & Ceil(Month(TempDate)/3) AS CalendarQuarter,

Year(TempDate) AS CalendarYear,

// Calendar Date Names

WeekName(TempDate) as CalendarWeekNumberAndYear,

MonthName(TempDate) as CalendarMonthAndYear,

QuarterName(TempDate) as CalendarQuarterMonthsAndYear,

// Start Dates

DayStart(TempDate) as CalendarDayStart,

WeekStart(TempDate) as CalendarWeekStart,

MonthStart(TempDate) as CalendarMonthStart,

QuarterStart(TempDate) as CalendarQuarterStart,

YearStart(TempDate) as CalendarYearStart,

// End Dates

DayEnd(TempDate) as CalendarDayEnd,

WeekEnd(TempDate) as CalendarWeekEnd,

MonthEnd(TempDate) as CalendarMonthEnd,

QuarterEnd(TempDate) as CalendarQuarterEnd,

YearEnd(TempDate) as CalendarYearEnd,

// Combo Date Examples

'Q' & Ceil(Month(TempDate)/3) & '/' & Year(TempDate) AS CalendarQuarterAndYear,

Year(TempDate) & '/' & 'Q' & Ceil(Month(TempDate)/3) AS CalendarYearAndQuarter,

'Wed ' & DayStart(WeekStart(TempDate) + 3) as CalendarWednesdays

RESIDENT TempCalendar ORDER BY TempDate ASC;

DROP TABLE TempCalendar;

LET vDateMin = Num(MakeDate(2000,1,1));

LET vDateMax = Floor(YearEnd(AddMonths(Today(), 12)));

LET vDateToday = Num(Today());

/* RANGOS DE FECHAS PARA SELECCION SECILLA */

/* RANGOS DE FECHAS PARA SELECCION SECILLA */

/* RANGOS DE FECHAS PARA SELECCION SECILLA */

// Assign current date to a variable. Makes INLINE below a little neater and ensures we don't cross midnight boundry.

LET vToday=today(1);

Ranges:

//This uses the "evaluate()" function to execute the input function text and convert it to actual date values.

LOAD DateRange, date(evaluate(RangeStart)) as RangeStart, date(evaluate(RangeEnd)) as RangeEnd

;

/* The INLINE data defines the Range Name, Starting date of the Range, and Ending date of the Range.

The Start/End values are defined using standard QV date functions.

Semicolon is used for a field delimeter because some of the functions contain commas.

*/

LOAD * INLINE [

DateRange; RangeStart; RangeEnd

Hoy; vToday; DayEnd(vToday)

Ayer; vToday-1; DayEnd(vToday-1)

SemanaActual; WeekStart(vToday); WeekEnd(vToday)

SemanaPasada; WeekStart(vToday,-1); WeekEnd(vToday, -1)

UltimasDosSemanas; WeekStart(today(1),-1); WeekEnd(today(1))

MesActual; MonthStart(vToday); MonthEnd(vToday)

MesPasado; MonthStart(vToday,-1); MonthEnd(vToday,-1)

UltimosDosMeses; MonthStart(vToday,-1); MonthEnd(vToday)

AñoActual; YearStart(vToday); YearEnd(vToday)

AñoPasado; YearStart(vToday,-1); YearEnd(vToday,-1)

Ultimos7; vToday-7;  DayEnd(vToday)

Ultimos3; vToday-3; DayEnd(vToday)

Penultimos7; vToday-7;  DayEnd(vToday-1)

Penultimos3; vToday-3; DayEnd(vToday-1)

] (delimiter is ';')

;

/*

Use IntervalMatch to link the Date field into multiple Range fields.

Doing a JOIN avoids creating a messy synthetic key.

*/

JOIN (Ranges) IntervalMatch (Fecha) LOAD RangeStart, RangeEnd RESIDENT Ranges;

// Because we did a JOIN, we may drop the the Start/End fields.

DROP FIELDS RangeStart, RangeEnd;

THEN REPLACE Load inline whit a English, and all really, but i´m chilean and "Fecha" whit your name of date, and asign the botton  whit variable "DateRange", text ='MesPasado', in English last month.

Saludos.

Fernando Peralta