Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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.
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
Not working in Qlik sense