Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
paulyeo11
Valued Contributor II

SET expression current month ok previous not ok

Hi All

I have below expression working fine for retuen current selected month amount :-

(

sum({$

<

year = {$(=max(year))},

Month = {"<=$(=max({<year={$(=max(year))}>} Month))>$(=max({<year={$(=max(year))}>} Month)-1)"}

>

}   Amount/1000)

)

I try to modify the above expression to below , in order to display previous month sales :-

(

sum({$

<

year = {$(=max(year))},

Month = {"<=$(=max({<year={$(=max(year))}>} Month))>$(=max({<year={$(=max(year))}>} Month)-2)"}

>

}   Amount/1000)

)

But it return null value. Can some one advise me where go wrong ?

Paul

1 Solution

Accepted Solutions
alexdataiq
Contributor III

Re: SET expression current month ok previous not ok

You could simplify those expressions by just using:

Current Month:

Sum({$< year = {$(=max(year))}, month = {$(=Max(month))}>} Amount/1000)

Past Month:

Sum({$< year = {$(=max(year))}, month = {$(=Max(month)-1)}>} Amount/1000)

But I would suggest create a variable for your previous Month to take into account January, something like:

vPreviousMonth

= If(Max(month) - 1 = 0, 12, month)

And use it in your expression:

Sum({$< year = {$(=max(year))}, month = {$(vPreviousMonth)}>} Amount/1000)

Cheers

3 Replies
paulyeo11
Valued Contributor II

Re: SET expression current month ok previous not ok

my QV Doc

alexdataiq
Contributor III

Re: SET expression current month ok previous not ok

You could simplify those expressions by just using:

Current Month:

Sum({$< year = {$(=max(year))}, month = {$(=Max(month))}>} Amount/1000)

Past Month:

Sum({$< year = {$(=max(year))}, month = {$(=Max(month)-1)}>} Amount/1000)

But I would suggest create a variable for your previous Month to take into account January, something like:

vPreviousMonth

= If(Max(month) - 1 = 0, 12, month)

And use it in your expression:

Sum({$< year = {$(=max(year))}, month = {$(vPreviousMonth)}>} Amount/1000)

Cheers

paulyeo11
Valued Contributor II

Re: SET expression current month ok previous not ok

Hi Alejandro

Thank you very much for your advise. I notice that after you simplify the expression , now user must select current month and year. In fact i have make a lot of change to avoid select select month and year. So the same expression i can use in QS.

Paul

Community Browser