Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Brossillon
Partner - Contributor
Partner - Contributor

Soucis de Date

Bonjour,

Je n'arrive pas à comparer deux dates pour calculer une recence. 

Je fais le maximum de la date - la date sur la ligne en cours. 

A chaque fois que j'essaie une fonction il me dis script error.

RFM:
LOAD
ID_Client as ID_Client,
// MakeDate(2017,12,01) - max(Date) as RFM_Recence,
(max(Date) - floor(Date)) as RFM_Recence,
sum(Quantite*Prix_Vente) as RFM_Montant,
count(distinct Source.Numero_Facture) as RFM_Frequence
RESIDENT Source
GROUP BY ID_Client
ORDER BY ID_Client;

 

Voici le format de date : 

01/12/2017

Et voici ce que ca me sort  quand je fais ID_Client, max(Date) et le calcul de la fréquence:

ID_Client,Max,Frequence
13085,43070.323611111,2
13078,43070.379166667,1
15362,43070.380555556,1
18102,43070.391666667,1
12682,43070.394444444,1
18087,43070.405555556,2
13635,43070.406944444,1

 

J'aimerai obtenir cela : 

"ID_Client","Montant","Frequence","Recence"
,2638958.18,8752,0
12346,-64.68,17,325
12347,5633.32,8,1
12348,2019.4,5,74

1 Solution

Accepted Solutions
christophebrault
Specialist
Specialist

 

Voici un script qui fonctionne et crée une table client:

TMP:
load * inline [
ID_Client,Num,Montant,Frequence,Date
14154,49857,32,1,09/12/2019
12346,491725,45,1,14/12/2017
12346,491742,22.5,1,14/12/2017
12346,491744,22.5,1,14/12/2017
12346,492718,22.5,1,18/12/2017
12346,492722,1,1,18/12/2017
12346,493410,22.5,1,04/01/2018
12346,493412,22.5,1,04/01/2018
12346,494450,22.5,1,14/01/2018
12346,495295,22.5,1,22/01/2018
12346,C495800,-103.5,1,26/01/2018
12346,499763,27.05,5,02/03/2018
12346,513774,142.31,19,28/06/2018
12346,C514024,-328.54,10,30/06/2018
12346,C525099,-1,1,04/10/2018
12346,C525274,-4.5,1,04/10/2018
12346,541431,77183.6,1,18/01/2019
12346,C541433,-77183.6,1,18/01/2019
];
MaxDate:
LOAD Max(Date) AS MaxDate Resident TMP;

Let vMaxDate = Peek('MaxDate');
Drop Table MaxDate;

CLIENT:
LOAD ID_Client,
Date('$(vMaxDate)') as maxDate,
Date(DateClient) as DateClient,
'$(vMaxDate)'-DateClient as Recence
;
LOAD ID_Client,Max(Date) as DateClient
Resident TMP
Group By ID_Client;
Drop Table TMP;

Inscrivez vous à ma Newletter Qlik
DoNotMissQlik- Connect with me on Linkedin

View solution in original post

5 Replies
christophebrault
Specialist
Specialist

Bonjour,

 

Si je comprends, tu as plusieurs lignes par ID_Client et donc deux dates que tu veux comparer (la Max et la Min ?)

Dans ton script, tu fais un Floor(Date), or Floor() n'est pas une fonction d'aggrégation comme Max. Essaie d'utiliser Min() à la place je pense.

Inscrivez vous à ma Newletter Qlik
DoNotMissQlik- Connect with me on Linkedin
Brossillon
Partner - Contributor
Partner - Contributor
Author

Bonjour,

 

En effet j'ai plusieurs lignes de factures par clients, voici un exemple sur ce client :

ID_Client,Num,Montant,Frequence,Date
12346,491725,45,1,14/12/2017
12346,491742,22.5,1,14/12/2017
12346,491744,22.5,1,14/12/2017
12346,492718,22.5,1,18/12/2017
12346,492722,1,1,18/12/2017
12346,493410,22.5,1,04/01/2018
12346,493412,22.5,1,04/01/2018
12346,494450,22.5,1,14/01/2018
12346,495295,22.5,1,22/01/2018
12346,C495800,-103.5,1,26/01/2018
12346,499763,27.05,5,02/03/2018
12346,513774,142.31,19,28/06/2018
12346,C514024,-328.54,10,30/06/2018
12346,C525099,-1,1,04/10/2018
12346,C525274,-4.5,1,04/10/2018
12346,541431,77183.6,1,18/01/2019
12346,C541433,-77183.6,1,18/01/2019

Je souhaite calculer sa recence. 

Donc la date max sur l'ensemble du fichier - la date max pour ce client.

Et je veux le résultat en nombre de jour. 

Pour ce client je dois obtenir 325 jour car sa date max est 18/01/2019 et la date max du fichier est 09/12/2019

 

christophebrault
Specialist
Specialist

 

Voici un script qui fonctionne et crée une table client:

TMP:
load * inline [
ID_Client,Num,Montant,Frequence,Date
14154,49857,32,1,09/12/2019
12346,491725,45,1,14/12/2017
12346,491742,22.5,1,14/12/2017
12346,491744,22.5,1,14/12/2017
12346,492718,22.5,1,18/12/2017
12346,492722,1,1,18/12/2017
12346,493410,22.5,1,04/01/2018
12346,493412,22.5,1,04/01/2018
12346,494450,22.5,1,14/01/2018
12346,495295,22.5,1,22/01/2018
12346,C495800,-103.5,1,26/01/2018
12346,499763,27.05,5,02/03/2018
12346,513774,142.31,19,28/06/2018
12346,C514024,-328.54,10,30/06/2018
12346,C525099,-1,1,04/10/2018
12346,C525274,-4.5,1,04/10/2018
12346,541431,77183.6,1,18/01/2019
12346,C541433,-77183.6,1,18/01/2019
];
MaxDate:
LOAD Max(Date) AS MaxDate Resident TMP;

Let vMaxDate = Peek('MaxDate');
Drop Table MaxDate;

CLIENT:
LOAD ID_Client,
Date('$(vMaxDate)') as maxDate,
Date(DateClient) as DateClient,
'$(vMaxDate)'-DateClient as Recence
;
LOAD ID_Client,Max(Date) as DateClient
Resident TMP
Group By ID_Client;
Drop Table TMP;

Inscrivez vous à ma Newletter Qlik
DoNotMissQlik- Connect with me on Linkedin
Brossillon
Partner - Contributor
Partner - Contributor
Author

Et bien parfait merci ! 

Après une journée d'échec, tu as égayer ma journée.

 

christophebrault
Specialist
Specialist

Avec plaisir 👍

Inscrivez vous à ma Newletter Qlik
DoNotMissQlik- Connect with me on Linkedin