Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Dear all,
i need your support in order to solve a "little" problem.
I have a table like this
KEYID Start End etc etc
1 01/12/2019 31/03/2020 alfa beta
2 01/02/2020 31/03/2020 sdfs gddd
3 01/01/2020 29/02/2020 uytt uyyyy
For every KEYID i would like to create many lines as there are months of validity using a cycle.
The final result must be (for the KEYID 1) something like this
KEYID Start End Year validity Month validity etc etc
1 01/12/2019 31/03/2020 2019 12 alfa beta
1 01/12/2019 31/03/2020 2020 01 alfa beta
1 01/12/2019 31/03/2020 2020 02 alfa beta
1 0/12/2019 31/03/2020 2020 03 alfa beta
Thanks in advance for your help
Regards
Mauro
@mauvasco62 try below
Data
LOAD KEYID,
Start,
year(monthstart(Start,iterno()-1)) as Year ,
month(monthstart(Start,iterno()-1)) as Month
End,
etc1,
etc2
FROM Table
while monthstart(Start,iterno()-1)<=End;
@mauvasco62 like this for example ?
Data:
load * inline [
KEYID,Start,End,etc,etc1
1,01/12/2019,31/03/2020,alfa,beta
2,01/02/2020,31/03/2020,sdfs,gddd
3,01/01/2020,29/02/2020,uytt,uyyyy
];
left join
load distinct KEYID,Num(Month(Date(Start + IterNo() - 1)),'00') as [Month validity],Year(Date(Start + IterNo() - 1)) as [ Year validity] resident Data While Start + IterNo() - 1 <= End;
output:
@mauvasco62 try below
Data
LOAD KEYID,
Start,
year(monthstart(Start,iterno()-1)) as Year ,
month(monthstart(Start,iterno()-1)) as Month
End,
etc1,
etc2
FROM Table
while monthstart(Start,iterno()-1)<=End;
Thank you Kush,
it works fine.
Have a nice day
Mayri