Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
hermanitor
Contributor III
Contributor III

Creation of Table Using a Date Field in a Table

Hi.
I have a table that looks like the following

Asset IDDate Registered
A05/02/2008
B21/06/2016
C04/10/2020


Need to loop through this table and for each asset ID and I would like to create a new table which uses the date and creates years from the date registered so I can then fill the data from another measures tables with the spend per asset per defined year...So I want a table like this

Asset IDDate RegisteredYear #Start YearEnd Year
A05/02/2008Year 105/02/200804/02/2009
A05/02/2008Year 205/02/200904/02/2010
A05/02/2008Year 305/02/201004/02/20011
A05/02/2008Year n05/02/2021 


Does this make sense what I require?
Any queries, please ask
Thanks

 

 

1 Solution

Accepted Solutions
MayilVahanan

HI @hermanitor 

Try like below


LOAD *, Year(DateRegistered)+IterNo()-1 as Year, 'Year '& IterNo() as YearName, MakeDate(Year(DateRegistered)+IterNo()-1, Month(DateRegistered), Day(DateRegistered)) as StartYear
, MakeDate(Year(DateRegistered)+IterNo()-1+1, Month(DateRegistered), Day(DateRegistered)-1) as EndYear
INLINE [
Asset ID, DateRegistered
A, 05/02/2008
B, 21/06/2016
C, 04/10/2020
]while Year(DateRegistered)+IterNo()-1 <= Year(Today()) ;

O/p:

MayilVahanan_0-1615456770075.png

 

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

4 Replies
MayilVahanan

HI @hermanitor 

Try like below


LOAD *, Year(DateRegistered)+IterNo()-1 as Year, 'Year '& IterNo() as YearName, MakeDate(Year(DateRegistered)+IterNo()-1, Month(DateRegistered), Day(DateRegistered)) as StartYear
, MakeDate(Year(DateRegistered)+IterNo()-1+1, Month(DateRegistered), Day(DateRegistered)-1) as EndYear
INLINE [
Asset ID, DateRegistered
A, 05/02/2008
B, 21/06/2016
C, 04/10/2020
]while Year(DateRegistered)+IterNo()-1 <= Year(Today()) ;

O/p:

MayilVahanan_0-1615456770075.png

 

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
hermanitor
Contributor III
Contributor III
Author

Thanks Mayil.  
Thought I needed a loop, but was going around this the wrong way....


 

MayilVahanan

Welcome. Happy to help you. 

And Appreciated, you thought correctly. Hope in future, will do it yourself.

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
hermanitor
Contributor III
Contributor III
Author

Just fyi.....
Was using the above table with my qvd load and found that it really did not like dates like 01/11/15....(DD-MM-YY)....
Had to load the table beforehand and take a day of where the dd was 01....
Quite an interesting issue to be honest

Steve