# QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
CUSTOMERS ONLY: Now accepting customer applications for the 2023 Luminary Program: SUBMIT NOW
cancel
Showing results for
Did you mean:
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...
12 Replies
MVP & Luminary

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)

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

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...
MVP & Luminary

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

Specialist

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

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

Creator

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))

Partner - Creator II

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