# QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Not applicable

## 2 digit year field how to sort from hi to lo ?

Hi All

I am using below code to get 2 digit for year :-

Right(year(date),2)           as [year_],

I am not able to sort the year in sequences from hi to lo

Any work around ?

PAul

1 Solution

Accepted Solutions
MVP

## Re: 2 digit year field how to sort from hi to lo ?

Paul

You can create a dual for this, and sort it numerically, like this.

Dual(Right(Year(date), 2), YearStart(date))

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
18 Replies
Contributor

## Re: 2 digit year field how to sort from hi to lo ?

Simply because year is now traited as Text o String format. Format your year using Date() function to retain it as Year. See line of script below:

Date(date,'YY') as [year_]

It is very important to keep year in it's original format. Hope it helps.

Thanks,

Bill

Contributor

Paul,

Not applicable

## Re: Re: 2 digit year field how to sort from hi to lo ?

Hi Bill

Hi Sir

I use

Date(date,'YY') as [year_]

i get duplicated year. any work around ?

MVP

## Re: 2 digit year field how to sort from hi to lo ?

Hi Paul,

Right(year(date),2)           as [year_], -- Right() will give you the result in string

you use this

Date(date, 'YY') as [year_] this will give you the year in date (numeric)

Hope this helps you.

Regards,

Jagan.

MVP

## Re: 2 digit year field how to sort from hi to lo ?

Try:

=Num(Mod(Year(date),100),'00')

You can try it in he script as well.

PFA

Not applicable

## Re: 2 digit year field how to sort from hi to lo ?

hi paul may i know why you use like that

Not applicable

## Re: Re: 2 digit year field how to sort from hi to lo ?

Hi Nir

I am lazy to write code for year field :-

=

IF(year='2014','14',

IF(year='2013','13',

IF(year= '1997' ,'97',

IF(year= '1998' ,'98',

IF(year= '1999' ,'99',

IF(year= '2000' ,'00',

IF(year= '2001' ,'01',

IF(year= '2002' ,'02',

IF(year= '2003' ,'03',

IF(year= '2004' ,'04',

IF(year= '2005' ,'05',

IF(year= '2006' ,'06',

IF(year= '2007' ,'07',

IF(year= '2008' ,'08',

IF(year= '2009' ,'09',

IF(year= '2011' ,'11',

IF(year= '2012' ,'12',

IF(year= '2010','10'))))))))))))))))))

Not applicable

## Re: Re: 2 digit year field how to sort from hi to lo ?

Hi Jagan

if i use :-

Date(date, 'YY') as [year_] this will give you the year in date (numeric)

My year field unable to sort like below :-

98 99 10 11

Not applicable

## Re: Re: 2 digit year field how to sort from hi to lo ?

Hi Tres

Notice that it not able to sort . i need it :-

96  99 00 11 12