Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
jmialoundama
Specialist
Specialist

Loop for add month to date during two years

Hi,

I'm new to creating loops

I have this data : 

jmialoundama_0-1665101798066.png

I need to create a loop in the load script to add a number of months (the "Period" column indicates the number of months to add to the date) for 2 years.

The calculation is as follows : Date + period during 2 years. 

When I have all the dates for 2 years, the loop stops

 

Can i help me please ? Thanks in advance 🙂

Labels (4)
3 Replies
Vegar
MVP
MVP

I'm not completely understanding  your issue, but when reading it I get an idea of what you are trying to do. Maybe this load while will help.

 

Load

Dayname([Date] + iterno() - 1 ) as Date,

dayname(addmonths([Date] + iterno() - 1, Period))  as DatePeriod

Resident Source 

While  [Date] + iterno() - 1 < addyears([Date],2);

 

jmialoundama
Specialist
Specialist
Author

Hi @Vegar ,

I tested the script and it generates many dates.

However, it generates all the dates of the month for me, whereas I would like it to generate only two dates (date_generate_1 and date_generate_2).

Date_generate_1 : Date + Period

Date_generate_2 : Date_generate_1 + Period

This is what I have : 

jmialoundama_0-1665396234240.png

How can i do it ? 

Vegar
MVP
MVP

I see, I missunderstood you in my first reply.

I think this is what you are looking for.

LOAD
  Date,
  Period,
  AddMonths(Date,Period) as Date1,
  AddMonths(Date,Period*2) as Date2
Inline [
  Date,      Period
  01/01/2022,12
  05/03/2022,9
  04/05/2022,3
  10/11/2022,9
];


> Assuming that your [Date] field is recognized as a date and not a string by your application.