Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Hamdi_G
Contributor III
Contributor III

Différence groupée avec conditions Qlik sense

J'aimerais par une boucle qui pour chaque numéros d'erreurs inférieure à 600 va rechercher la prochaine valeur fixe de 607 puis faire une différence entre les deux dates correspondante et ainsi de suite pour enfin faire la somme des différences obtenues pour chaque id

1 Solution

Accepted Solutions
Taoufiq_Zarra

@Hamdi_G 

Maye be :

Datatmp:

LOAD ID, 
     erreur, 
     Timestamp(dates) as dates
FROM
.\ClasseurTest.xlsx
(ooxml, embedded labels, table is Feuil1);

Data:
noconcatenate
load  * resident Datatmp where (erreur <600 or erreur = 607 ) order by ID,dates  ;

drop table Datatmp;



tmp2:
noconcatenate

load *,
if(rowno()=1,0,if(erreur=607,peek(value3),if(previous(erreur)<607,peek(value3),peek(value3)+1))) as value3, 
if(erreur=607 and previous(erreur)=607,1,0) as Flog2 
resident Data;

drop table Data;


tmp3:

load ID,value3,Timestamp(Max(dates)) as Maxdates,Timestamp(Min(dates)) as Mindates,Time(Timestamp(Max(dates))-Timestamp(Min(dates))) as Interval resident tmp2 where Flog2=0 group by ID,value3;

drop table tmp2;



Final:

load ID ,Time(sum(Interval)) as Cumul resident tmp3 group by ID;


drop table tmp3;
Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

1 Reply
Taoufiq_Zarra

@Hamdi_G 

Maye be :

Datatmp:

LOAD ID, 
     erreur, 
     Timestamp(dates) as dates
FROM
.\ClasseurTest.xlsx
(ooxml, embedded labels, table is Feuil1);

Data:
noconcatenate
load  * resident Datatmp where (erreur <600 or erreur = 607 ) order by ID,dates  ;

drop table Datatmp;



tmp2:
noconcatenate

load *,
if(rowno()=1,0,if(erreur=607,peek(value3),if(previous(erreur)<607,peek(value3),peek(value3)+1))) as value3, 
if(erreur=607 and previous(erreur)=607,1,0) as Flog2 
resident Data;

drop table Data;


tmp3:

load ID,value3,Timestamp(Max(dates)) as Maxdates,Timestamp(Min(dates)) as Mindates,Time(Timestamp(Max(dates))-Timestamp(Min(dates))) as Interval resident tmp2 where Flog2=0 group by ID,value3;

drop table tmp2;



Final:

load ID ,Time(sum(Interval)) as Cumul resident tmp3 group by ID;


drop table tmp3;
Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉