Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
laxmanqlik
Creator II
Creator II

help me to use of variable

i have a requirement that,

in table i have a year field with 2011,2012,2013,2014

now using a variable i need grab the last two values  even if another value is added to it

i.e, if we add 2015

i need to get 2014 and 2015

if we add another one 2016

i need to get 2015 and 2016

last two values i have to get.

12 Replies
Anonymous
Not applicable

Hi laxman,

If you need two variables to do it or if you want to make ranges:

vMaxYear = Max(Year)

vMinYear = Max({<Year = {"<$(vMaxYear)"}>}Year)

If you want it on same var to make selections with actions:

vMaxYear = Max(Year)

vYears = '('&Max(Year)&'|'&Max({<Year = {"<$(vMaxYear)"}>}Year)&')'

Regards

Colin-Albert

Let vMaxY1 = max(Year) ;

Let vMaxY2 = (vMaxY1 - 1) ;

Mark_Little
Luminary
Luminary

Hi,

Colin's answer should get them for you, But there are a few different ways you can do this.

If you could supply us some more information on what your are wanting to do with these years we could suggest the best approach.

i.e. Just display in a test box or feed into set analysis.

Mark

Anonymous
Not applicable

Hi Colin,

What happen if there isn't two consecutive years?

laxmanqlik
Creator II
Creator II
Author

i tried but it showing

in valid dimesion

laxmanqlik
Creator II
Creator II
Author

hi mark

i want to display it in a textbox

Not applicable

Hi ,

Colin's answer is precise but if you want the last two years for table having more than 1 distinct year , then use an additional 'if' statement for checking the count in the expression which Manuel has provided .

Mark_Little
Luminary
Luminary

Hi,

One way would be

=' Selected - ' & MAX(GetFieldSelections(Year)) & '-  Previous - ' & MAX(GetFieldSelections(Year )-1)

Mark

Anonymous
Not applicable

Could you share an example app?