Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Previous Month

Hello ppl!

I have a question!

Ived created a variable called vPreviousMonth =month(addmonths(max(Date_Clean),-1))

I want a straight table which shows current month i have selected (ive made that) and then i want the previous table to show previous month

e.g. If i am in November i also want to see October - If i am in July, i also want to see June..

How do i make that expression?

My expression for currentmonth looks like this:

=Sum({<Month=, Year=,2012={'>=$(=MonthStart(Max(2012)))<=$(=Max(2012))'}>}BuyPriceRealized)

I dont know if that expression is correct if not i would also like to know how the "right" way is to do it...

Thanks ALOT!!

1 Solution

Accepted Solutions
SunilChauhan
Champion II
Champion II

no change required in expression

see below code

first expression

Sum({$<Month={"$(vCurrMonth)"}>}Volume)

second expression

Sum({$<Month={"$(vLastMonth)"}>}Volume)

third expression

=Column(1)-Column(2)

hope this helps

Sunil Chauhan

View solution in original post

19 Replies
Not applicable
Author

I have only founded soulution where they use TODAY, -1 or -2 etc etc.. But i dont want it to be hardcoded As you can see my currentmonth is not hardcoded and changes every time i select a new month

Not applicable
Author

The only thing to note with the attached example is that the year may be confusing... For example, if you select Jan, the past month will be Dec, but it would be for the same year unless you specify otherwise.

shree909
Partner - Specialist II
Partner - Specialist II

Hi,

let us take example u have month field name( jan, feb, mar.......dec for year 2012

so u can create a variabe  vmonth = Month

and in the expression

=Sum({<Month={ '$(vmonth)'}, Year=2012)'}>}BuyPriceRealized)  this will show the month u have selected for year 2012

for previous year calculation  i would suggest take the month number and convert into previous month number and then convert into  month name in the expression..

Not applicable
Author

Thats okay cause i only have one year.

Not applicable
Author

But i already have current month i am in. I only need previous month

Not applicable
Author

Anybody else who have an suggestion?

Not applicable
Author

Your expression does not work e:/ But anyhow ived already made currentmonth Can u explain what u mean by converting? or give me an example - It should be previousmonth not previousyearmonth

Thanks in advanced!

SunilChauhan
Champion II
Champion II

why Not Use MonthYear

vCurrMonth== Max(MonthYear)

vPrevMonth==Date(addmonths(Max(MonthYear),-1),'MMM-YYYY')

and In Label Left(vCurrMonth,3) and Left(vPrevMonth,3)

hope this helps

Sunil Chauhan
Not applicable
Author

So i create a variable called vCurrMonth and a variable called vPrevMonth

What do i write in my expressions then for my straight table? Just the Variable???