Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
lavanya14
Contributor III
Contributor III

Urgent Help plz - For loop


Hi All,

I have a table called equipment and i need one more date column through loop lets say

ColumnA     ColumnB     ColumnC            NewDateColumn    

           1             a                      1234             3-Apr-2014

           2              b                      5678             3-Apr-2014

          3               c                      9876             3-Apr-2014

           1             a                      1234            4- Apr-2014

           2              b                      5678             4- Apr-2014

           3              c                      9876              4- Apr-2014

            1             a                      1234            5- Apr-2014

           2              b                      5678             5- Apr-2014

            3              c                     9876                5- Apr-2014

Basically I should have 3 days of date generated for the entire data available in my Table. Lets say for entire data available  in the table it should have 3-Apr-2014 and similarly the available data in table should have 4-Apr-2014.Same follows for 5-Apr-2014.

Any help would be appreciated.

Thanks in advance.

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Ahh, I missed the actual issue, it is not about format but the loop variable.

Try:

For i = 0 to  (vMax_Equ -vMin_Equ -1 )

Or,

For i = 0 to  ($(vMax_Equ) - $(vMin_Equ) -1)

View solution in original post

14 Replies
crusader_
Partner - Specialist
Partner - Specialist

Dear Lavanya,

Seems that you need just create a pivot table with Date as a first Dimension, but...

Could you provide result tables?

Thanks

Andrei

its_anandrjs

Can you share any sample data for this and let me know how you create a NewDateColumn column in the table

flipside
Partner - Specialist II
Partner - Specialist II

In script,

Data:

Load * inline [
ColumnA,     ColumnB,     ColumnC
1,                 a,                1234
2,                 b,                5678
3,                 c,                9876
]
;

left join (Data)
load * inline [
NewDate
3-April-2014
4-April-2014
5-April-2014
]
;

flipside

tresesco
MVP
MVP

May be like attached sample:

Let count=3;
Let StartDate=Num(Date#('3-4-2014', 'DD-MM-YYYY'));

For i=0 to $(count)-1

Load
*,
Date($(StartDate)+$(i)) as Date
;
Load * Inline [
ColumnA, ColumnB, ColumnC
 
1, a, 1234
 
2, b, 5678
 
3, c, 9876

];
Next i  ;

lavanya14
Contributor III
Contributor III
Author

Hi All,

Thanks for your quick response.

Let vMin_Equ = Today();   
Let vMax_Equ = Date(Today()+5);

For i =vMin_Equ to  vMax_Equ

vDate  = Date(vMin_Equ+$(i));

Equipment:
Load *,
1 as dummy,
('$(vDate)') as UI_Date
Resident EQUIPMENT;

Next


DROP Table EQUIPMENT;

When I run this code i am not able to see the UI_Date Field having the values 3-Apr,4-Apr,5-Apr. Instaed i see the below data in UI_Date.

UI_Date
06/07/2128
07/07/2128
08/07/2128
09/07/2128
10/07/2128
11/07/2128

But if i look at variable overview i see the values of

vMin_Equ = 3-Apr-2014

vMax_Equ = 8-Apr-2014.

Kindly suggestion what is causing the problem.

Thanks in advance.

lavanya14
Contributor III
Contributor III
Author

Hi,

Could you please tell if i dnt want to use the Inline table and make the script to pick the dates automatically from today() to today()+5 days in the inline table.

Thanks in advance.

tresesco
MVP
MVP

Try:

Date('$(vDate)' , 'DD-MMM-YYYY') as UI_Date

lavanya14
Contributor III
Contributor III
Author

Tried but No Luck

lavanya14
Contributor III
Contributor III
Author

Not sure what could be the reason of seeing different values in Variable Overview and in the Newly created field in backend..

In Variable Overview I am able to see the corect value for Vmin_Equ = 03-Apr and Vamx=04-Apr.