Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
matthewp
Creator III
Creator III

Expression calculation for last 12 months not including this month

I'm trying to create an expression calculation for last 12 months not including this month.

So for February it would be 2016 FEB to 2017 JAN

I tried

=Count({1<MMMYY ={'>=$(=Date(AddMonths(Today(), -13),'MMM-YY'))<=$(=Date(Today(), 'MMM-YY'))'}>} DISTINCT [MYID])/12

But it didn't work.

1 Solution

Accepted Solutions
matthewp
Creator III
Creator III
Author

Resolved this by doing the expression as:

=ROUND(COUNT({<[MYDATEFIELD]={'$(last12notinccur)'}>} DISTINCT MYID)/12)

and the variable "last12notinccur":

=  '>=' & date(AddMonths(MonthStart(Today()),-12), 'YYYYMM')   & '<=' & date(AddMonths(MonthStart(Today()),-1), 'YYYYMM')

View solution in original post

21 Replies
sunny_talwar

Is the format MMM-YY or MMMYY?

matthewp
Creator III
Creator III
Author

YYYYMM

sunny_talwar

Then give this a try

=Count({1<MMMYY ={'>=$(=Date(AddMonths(Today(), -13),'YYYYMM'))<$(=Date(MonthStart(Today()), 'YYYYMM'))'}>} DISTINCT [MYID])/12

Note: I added MonthStart to upper condition and changed from <= to <

matthewp
Creator III
Creator III
Author

hmm that gives me 0

sunny_talwar

Is there a space between YYYY MM or is it YYYYMM? If there is space, may be this

=Count({1<MMMYY ={'>=$(=Date(AddMonths(Today(), -13),'YYYY MM'))<$(=Date(MonthStart(Today()), 'YYYY MM'))'}>} DISTINCT [MYID])/12

matthewp
Creator III
Creator III
Author

Still 0,

no space between the dates.

If this helps, i have a trigger on the same sheet that uses

=  '>=' & date(AddMonths(MonthStart(Today()),-12), 'YYYYMM')   & '<=' & date(AddMonths(MonthStart(Today()),-0), 'YYYYMM')

Anil_Babu_Samineni

Why do you need 0 for second Equation, May be this?

=  '>=' & date(AddMonths(MonthStart(Today()),-12), 'YYYYMM')   & '<=' & date(MonthStart(Today()), 'YYYYMM')

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
sdmech81
Specialist
Specialist

try this:
=Count({1<num(MMMYY) ={'>=$(num=Date(AddMonths(Today(), -13),'YYYY MM')))<$(=Date(MonthStart(Today()), 'YYYY MM'))'}>} DISTINCT [MYID])/12
Wts tht MMMYY??
sdmech81
Specialist
Specialist

Plss attach application..