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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: 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
pho3nix90
Creator II
Creator II

I would suggest the following.

IN the script editor do the following resident load

Data:

LOAD * INLINE [

    YearField

    "2011,2012,2013,2014,2016"

];

We will assume the above is the data set for this example, from the above do a resident load

LOAD

YearField,

SubField(YearField,',') as FixedYearField

Resident Data;

It will create individual records for each year, and link back to the original text.

Now in the chart expression use the following:

Latest

Max(FixedYearField,1)

Second

Max(FixedYearField,2)

Just put the above in the variables you need

pho3nix90
Creator II
Creator II

Reading replies I might have misunderstood your explanation of the year. If it is just a normal year field then the below will do the trick, just replace FixedYearField with your field

Latest

Max(FixedYearField,1)


Second

Max(FixedYearField,2)

Or use this. set a variable with the below code

='Max(FixedYearField,$1)'

And you can now use a single variable to call records like below, for this example the variable is called vtest.

Now to  call the latest year, do

$(vtest(1))

Second latest

$(vtest(2))

vtest.PNG

susovan
Partner - Specialist
Partner - Specialist

Hi laxman,

Try this,

Warm Regards,
Susovan