Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
entsh
Contributor II
Contributor II

calculate with condition

hi

please see the below table

form coderowdate1date2 
12312001/1/12001/1/2 
12322001/1/22001/1/4 
12332001/1/42001/1/5 
12412001/1/62001/1/8 
12422001/1/82001/1/9 
12432001/1/9

2001/1/15

 
12442011/1/15

2011/1/19

 
12452011/1/19

2011/1/22

 
12512011/1/15

2011/1/19

 
12522011/1/19

2011/1/22

 

 

I want a solution through Script :

(date2 in row =3)  - (date1 in row=1 )

for example for code 123 = date2 in row3(2001/1/5)-date1 in row1(2001/1/1)=4 days

result

form coderesult 
1234 
1249 
125null 
1 Solution
4 Replies
sasikanth
Master
Master

HI,

Try below

Load FormCode, MaxDate-MinDate as ResultDays;

Load

FormCode,

min(date1) as MinDate,

Max(date2) as MaxDate

from Table

group by FormCode;

 

*Preceding Load helps to calculate duration. 

Saravanan_Desingh

Try this,

tab1:
LOAD * INLINE [
    form code, row, date1, date2
    123, 1, 1/1/2001, 1/2/2001
    123, 2, 1/2/2001, 1/4/2001
    123, 3, 1/4/2001, 1/5/2001
    124, 1, 1/6/2001, 1/8/2001
    124, 2, 1/8/2001, 1/9/2001
    124, 3, 1/9/2001, 1/15/2001
    124, 4, 1/15/2011, 1/19/2011
    124, 5, 1/19/2011, 1/22/2011
    125, 1, 1/15/2011, 1/19/2011
    125, 2, 1/19/2011, 1/22/2011
];

Left Join(tab1)
LOAD [form code], FirstSortedValue(date2,row=3) - FirstSortedValue(date1,row=1) As Result
Resident tab1
Group By [form code]
;
entsh
Contributor II
Contributor II
Author

thanks a lot ,its ok  but when i have only 1 form code :

 

 

 

tab1:
LOAD * INLINE [
    form code, row, date1, date2
       125, 1, 1/15/2011, 1/19/2011
   ];
];

Left Join(tab1)
LOAD [form code], FirstSortedValue(date2,row=3) - FirstSortedValue(date1,row=1) As Result
Resident tab1
Group By [form code]
;

 

 

result is wrong

form coderesult 
1254 

 

it should be:

form coderesult 
125-