Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
capriconuser
Creator
Creator

chnage year in date field in qlikview

i have following dates

01/01/2009

01/02/2010

01/04/2011

now i want to change year in date field.. i dont want to create new year field 

i tried this 

 

load 
ID,
fIDate,
if(Year(fIDate) = 2009, '2010',
     if(Year(fIDate) = 2010, '2009',
     if(Year(fIDate) = 2011, '2012'
     ))) as I_Year,

FROM 
.....

 

but this seems like creating new year field .. but i want to change year only in date colmn.. how i do this 

 

Labels (3)
9 Replies
sasikanth
Master
Master

HI, 

I couldn't sense any logic sequence  from your requirement, however if you want to add a year or any number of months you can use AddMonts function

 

Addmonths(fIDate, 12) as fIDate

 

if this is not the solution you are looking for then do let us know the requirement clearly 

 

 

 

capriconuser
Creator
Creator
Author

@sasikanth 

my question is 

in date field there is year and i want to swap these years in date field

like if i have dates like these

01/01/2009
01/02/2010
01/04/2011

 

then i want like this 

01/01/2010

01/02/2009

01/04/2012

 

hope u understand 

 

sasikanth
Master
Master

@capriconuser 

use below condition 

if(match(year(date),'2009'),AddMonths(date,12), if(match(year(date),'2010'),AddMonths(date,-12),
if(match(year(date),'2011'),AddMonths(date,12)))) as fIDate

 

capriconuser
Creator
Creator
Author

why u did 12 and -12 ? what if there is 2019 and want to change to 2020 then? @sasikanth 

sasikanth
Master
Master

@capriconuser 

as per your requirement it is only one year to increase / decrease so i used 12 ,  

you should explain your full requirement, bits and pieces wont help us 

1, is there any logic behind Year switch ?? 

2, What is date field range??

3, in total how many years are there to swap ??

4, what about future years ??

capriconuser
Creator
Creator
Author

there is no logic just want to change original data into dummy data so want to swap years ..

year range is 2009 to 2021

so for 2009 this change to 2008

2010 to 2009, 2011 to 2010, 2012 to 2011, 2013 to 2012 , 2014 to 2013 , 2015 to 2014, 2016 to 2015, 2017 to 2016, 2018 to 2017 , 2019 to 2018, 2020 to 2019, 2021 to 2020

 

 

sasikanth
Master
Master

simple

use

addmonths(fIDate,-12) as fIDate

OR 

addYears(fIDate,-1) as fIDate

 

 

capriconuser
Creator
Creator
Author

in every criteria whether year is 2015 or 2016 or any thing else ?

sasikanth
Master
Master

yes, it works for all years.