Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
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
marcus_sommer

Max(month) respectively Max(month) - 1 will return the current and the prevoius month regarding to the selections.

- Marcus

Not applicable

Use two expression  one is for current month and previous month.

example:  expression for current month: =sum({<Month={"=$(=Max(Month))"}>}Sales)

               expression for previous month: =sum({<Month={"=$(=Max(Month)-1)"}>}Sales)

daniel_kusiak
Creator II
Creator II

For previous month you can use:

Sum({$<date={'=MonthsEnd(1,(date),-1)'}, Sales)

Not applicable

You can create variables

Curr: vCurrMon

Prev : vPrevMon

vCurrMon = =month(date(Month,'MMM'))

vPrevMon = date(AddMonths((date(Month,'MMM')),-1,MMM'),'MMM')

thanks

abhijitnalekar
Specialist II
Specialist II
Author

Thanks Marcus,

previous month formula is not working properly when we select January month.

what should i do if i want to show current month when we are showing all data (there is nothing filtered).

Regards,

Abhijit

Regards,
Abhijit
keep Qliking...
Help users find answers! Don't forget to mark a solution that worked for you!
marcus_sommer

Yes this is right by turn of the year it won't work (so simply). For this you could use a MonthCounter within the Master-Calendar: Re: Howto make a variable to calculate quarters regarding year changes?

Another possibility is the use of addmonths() maybe in this way:

month(max(Date)) // current month

month(addmonths(max(Date), - 1)) // previous month

- Marcus

Anonymous
Not applicable

Current month :sum({<Month={"=$(=Max(Month))"}>}Sales)

Previous month :sum({$<Month={"=$(=Max(Month)-1)"}>}Sales)

Anonymous
Not applicable

Try this.

Current Year = Year(Max(Date))

Current Month = month(Max(Date))

Previous Year = =Year(addmonths(max(Date) ,- 1))

Previous Month = Month(addmonths(max(Date) ,- 1))

Pulkit_Thukral
Partner - Creator II
Partner - Creator II

Current_Month={"$(=DATE(FLOOR(MonthStart(max(Date))),'MMM'))"}

Last_Month={"$(=DATE(FLOOR(MonthStart(AddMonths(max(Date),-1))),'MMM'))"}