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

Get Current month and previous month

Hi All,

I need help...

I want to calculate current month and previous month. Eg. Suppose all data is selected then values show current month(May) data and previous month(April) data, and if user click on April month filter then variable need to show current month as April and previous month as March. Hope you understand the requirement.

Regards, Abhijit

Regards,
Abhijit
keep Qliking...
Help users find answers! Don't forget to mark a solution that worked for you!
12 Replies
vatsalajmera5
Contributor II
Contributor II

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.

sandeep_sarawgi
Partner - Contributor III
Partner - Contributor III

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
MMCGLAESASAA
Contributor III
Contributor III

Not working in Qlik sense