11 Replies Latest reply: Jan 22, 2018 4:25 AM by RAVI SHINGE

# Create For loop for 36 Months

Hello Guys,

Could you please let me know how do I create a

For loop for 36 months .

Thanks,

Ravi

• ###### Re: Create For loop for 36 Months

In a load script you can create a FOR loop like this:

FOR month=1 TO 36

......

AUTOGENERATE 1;

NEXT

In a visualization you can use the ValueLoop()-function to generate within an expression:

AddMonths(MakeDate(2018,1,1), ValueLoop(0,35))     // to be used for instance in a calculated dimension.

• ###### Re: Create For loop for 36 Months

FOR month=1 TO 36

I have to use column name like Duration. How do I use this column DURATION instead of 1 to 36 . ?

DURATION column has value of 36 . So I want For loop starting from 1st month to 36th month.

So  I need something  as mentioned below .

FOR x=1 to "DURATION"

Thanks,

Ravi

• ###### Re: Create For loop for 36 Months

So the Duration belongs to a table with many rows right? Do you want 36 times the number of rows? Need to know more about the table structure you have and what kind of table structure you need to produce....

• ###### Re: Create For loop for 36 Months

hello ,

here is my code :-

[DataNew1]:

"Product Line",

"Impact month",

"Duration"

FROM [lib://AttachedFiles/Complexity_Mix.xlsx]

(ooxml, embedded labels, header is 1 lines, table is Model);

FOR month=1 TO 36  (Here 36 is the value in Column "Duration" ) , This value may change so I wanted it to be dynamic.

So I want For loop starting from 1st month to 36th month.

FOR x=1 to "DURATION" ,   I want to use column name in the FOR LOOP  not the numbers .

Thanks,

Ravi

• ###### Re: Create For loop for 36 Months

So what will be the variation for each of the 36 months? One monts difference? Anything else?

• ###### Re: Create For loop for 36 Months

Yes Yes one month difference .

• ###### Re: Create For loop for 36 Months

You can use while to iterate a number of times and produce many rows:

[DataNew1]:

"Product Line",

"Duration"

FROM [lib://AttachedFiles/Complexity_Mix.xlsx]

(ooxml, embedded labels, header is 1 lines, table is Model)

WHILE IterNo()<=Duration;

I assume here that "Impact month" is a real date and not just a mont number or month name...

• ###### Re: Create For loop for 36 Months

Thanks ,

Could you please Use FOR LOOP ?

• ###### Re: Create For loop for 36 Months

That's exactly what I did in my very first response. If you tell us what your source table and result table should look luke it would be easier to give a good suggestion or solution.

• ###### Re: Create For loop for 36 Months

Thanks Petter,

[DurationFlow3]:

"Impact month",  // has value of 12

"Duration" // has value of 4

FROM [lib://AttachedFiles/Complexity_Mix.xlsx]

(ooxml, embedded labels, header is 1 lines, table is Model);

Let vImpact_Month=Peek('Impact month',0,DurationFlow3);

For i=1 to 36

For x=1 to 4    // here I want ( For x= 1 to Duration)  from table  [DurationFlow3]:    Rest all code is fine for me , Just need this for loop ...

if \$(i) =1 then

test:

\$(i) as Month,

\$(x) as Month2,

\$(vImpact_Month) as value

AutoGenerate 1;

ELSE

test:

\$(i) as Month,

\$(x)+(\$(i)-1) as Month2,

\$(vImpact_Month) as value

AutoGenerate 1;

ENDIF

NEXT x;

NEXT i;

• ###### Re: Create For loop for 36 Months

Thanks Petter ,

I was able to Solve the issue . I did something like this  and it worked for me .....Thanks a lot for the support , I appreciate your suggestions

let vDuration= Peek('Duration',0,Duration_table);

for x=1 to \$(vDuration)