Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Pedro_112329
Contributor
Contributor

Calculate Previous Period for Months Selected

Hi Community

I am really struggling do this calculation : I have a date field (CalendarMonthId) which the user selects in the Calendar. The atered state Pivot_CalendarFree is triggered when the user selects the calendar.  What I want to do is calculating the previous period depending the number of months the user selects . Por example :

if the user selects Jan-2023, the result must be Dez-2022.

if the user selects more than one month , lets say Jan-2023 and Dez-2022 , the result must be Nov-2022 and Oct-2022.

And if the user selects Jan-2023 Dez 2022 and for example Sep 2022 , the result must me Nov-2022 , Oct-2022. and Aug 2022.

 

I created two variables : vMax = Date(Addmonths(max({PivotCalendar_R1M} CalendarMonthID),-$1),'YYYYMM') and vMin =  Date(Addmonths(mIN({PivotCalendar_R1M} CalendarMonthID),-$1),'YYYYMM') and in a listbox I insert the following expression :  

aggr(only({<CalendarMonthID= {">=$(=$(vAux_Calendar_ValueR1M_MiN(count({Pivot_CalendarFree} distinct CalendarMonthID)+1)))<=$(=$(vAux_Calendar_ValueR1M_Multiple(count({Pivot_CalendarFree} distinct CalendarMonthID)+1)))" }>}CalendarMonthID),CalendarMonthID).

With this expression I can fullfill the two first conditions but the last one , I cannot . 

Please can you help me in this issue ?

Thanks in Advance 

Labels (1)
1 Reply
Rohan
Specialist
Specialist

Hi,

As far as I understood, you need to define 2 date ranges:
  1) the date range where user will selects : {">$(=min(Date))<=$(=max(Date))"}

 2) the previous date range that will be calculated as :

  {">=$(=addmonths(min(Date),-$(=count({<{">$(=min(Date))<=$(=max(Date))"}>}distinct Months)))) <=$(=min(Date))"};

Let me know in case of any queries.

Thanks & Regards,

Rohan.