Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

vatsalajmera5
New Contributor II

Re: Get Current month and previous month

Hi,

The easiest solution to this would be to the monthAgo calculation in the Qlik Calender.

create an auto calendar for the date field you are trying to visualize by using the Derive fields function in the calendar script. ( I can attach the complete auto calendar script if needed)

ex:-  DERIVE FIELDS FROM FIELDS [date Field]

now, for current month the code in the measure field would be :

Sum( {$ < [Date.autoCalendar.MonthsAgo] = {'0'}>} sales)

U can change the 0 to 1,2,3 to go back to n last months.

Hope this helps.

Highlighted
Partner
Partner

Re: Get Current month and previous month

This is an old post, but if it helps anyone--consider adding this in your calendar script to identify current month (and year) records and prior month to that current month as 1 or else 0:

 

IF(MONTH(TempDate) = MONTH($(varMaxDate)) and
   Year(TempDate) = Year($(varMaxDate)),1,0) AS CurrentMonthFlag,


  IF(MONTH(TempDate) = MONTH(ADDMONTHS($(varMaxDate),-1))
    and if(Month(TempDate)=1,
           if(Year(TempDate)-1= Year($(varMaxDate))-1,1,0),
                    if(Year(TempDate)=Year($(varMaxDate)),1 ,0))=1,1,0)
                    AS PriorMonthFlag

Sandeep Sarawgi