Qlik Community

QlikView Creating Analytics

Discussion Board for collaboration related to Creating Analytics for QlikView.

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
chauhans85
Esteemed Contributor

Re: Previous Month

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

19 Replies
Not applicable

Re: Previous Month

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

Re: Previous Month

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
Valued Contributor II

Re: Previous Month

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

Re: Previous Month

Thats okay cause i only have one year.

Not applicable

Re: Previous Month

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

Not applicable

Re: Previous Month

Anybody else who have an suggestion?

Not applicable

Re: Previous Month

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!

chauhans85
Esteemed Contributor

Re: Previous Month

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

Not applicable

Re: Previous Month

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

Community Browser