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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
vardhancse
Specialist III
Specialist III

Current Month Vs Previous Month

Hi,

Created 2 variables:

vCurrentmonth=month(DateFull)

vPreviousmonth= Month(AddMonths(DateFull,-1))

Trying to build one expression:

Sum({<MonthName={'=$(vCurrentmonth)'}>}Actual) Now the value was coming correctly for the current month.

but when given previous month variable the value was same as current month:

Sum({<MonthName={'=$(vPreiousmonth)'}>}Actual)


can please do the needful.

4 Replies
thakkarrahul01
Creator
Creator

Logically, it looks correct. can you please add data and sample qvw file.

miguelbraga
Partner - Specialist III
Partner - Specialist III

First of all your second expression is wrong (bad typing), it should be something like this:

=Sum({<MonthName={'=$(vPreviousmonth)'}>}Actual)


Then previous month needs to calculate the year, so that when you have for example a current date of 31/01/2015, the previous month should be 12 (December) from the previous year 2014.



sunny_talwar

Is MonthName function just Month or does it include year information as well? May be be if you can share some data, it would be much more faster and easier to help

miguelbraga
Partner - Specialist III
Partner - Specialist III

You'll need to add something like this:

vPreviousYearMonth = {$(=Year(addmonths(max(Data),-1)))}

vPreviousmonth = Month(AddMonths(DateFull,-1))

=Sum({$<Year = {'=$(vPreviousYearMonth )'}, MonthName = {'=$(vPreviousmonth)'}>} Actual)

I think, this way you'll get what you want