Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
MAPSF1
Contributor III
Contributor III

Set Analysis Date Period

Hi, 

I am trying to create a set analysis calculation which includes a date period. I want to see the last 12 date periods combined in one sum. The PERIOD field is just a combination of the YEAR & MONTH. 

I created a variable (vCurrentPeriod) to house the Current PERIOD so that is a rolling calculation. 

 

Sum({<YEAR=, MONTH=, PERIOD={‘>=$(=vCurrentPeriod -11))<=$(=vCurrentPeriod)’}>} SALES )

 

Can anyone see where I am going wrong? 

Thanks in advance. 

5 Replies
stevejoyce
Specialist II
Specialist II

is period a date field formatted like YYYYMM ?

vCurrentPeriod:  =max(PERIOD)

Sum({<YEAR=, MONTH=, PERIOD={">=$(date(addmonths(date#('$(vCurrentPeriod)','YYYYMM'),-12),'YYYYMM')) and and <= $(vCurrentPeriod) "} >} SALES )

MAPSF1
Contributor III
Contributor III
Author

Yeah, the datefield is YYYYMM. 

stevejoyce
Specialist II
Specialist II

Ok, try what i posted.

vCurrentPeriod:  =max(PERIOD)

Sum({<YEAR=, MONTH=, PERIOD={">=$(date(addmonths(date#('$(vCurrentPeriod)','YYYYMM'),-12),'YYYYMM')) and and <= $(vCurrentPeriod) "} >} SALES )

MAPSF1
Contributor III
Contributor III
Author

thanks for the reply but there seems to be an error in the code? should there be a double and, and extra " marks? 

stevejoyce
Specialist II
Specialist II

quotes are fine.  i have an extract and, and a space.  try this.

Sum({<YEAR=, MONTH=, PERIOD={">=$(date(addmonths(date#('$(vCurrentPeriod)','YYYYMM'),-12),'YYYYMM')) and <=$(vCurrentPeriod) "} >} SALES )