Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
G3S
Creator III
Creator III

picking max of date in where clause

hi,

data is something like below.

POLCarrierVersionRatesValidityTEU
NaplesAAA202030/06/202015
NaplesAAA202031/12/202015

 

same Version can have multiple RatesValidity

need  TEU of the latest Ratevalidity as the result (second line in above table)

in the script,  in where clause, unable to use expression :

where max(RatesValidity)

Help please?

Labels (1)
4 Replies
Taoufiq_Zarra

Hi,

One solution :

Data:
LOAD * INLINE [
    POL, Carrier, Version, RatesValidity, TEU
    Naples, AAA, 2020, 30/06/2020, 15
    Naples, AAA, 2020, 31/12/2020, 15
];

output:
noconcatenate
load   POL, Carrier, Version, Date(Max(Date#(RatesValidity,'DD/MM/YYYY'))) as RatesValidity, FirstSortedValue(TEU,-Date#(RatesValidity,'DD/MM/YYYY')) as TEU resident Data group by POL, Carrier, Version;

drop table Data;

 

output :

Capture.PNG

Regards,
Taoufiq ZARRA

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

(you can mark up to 3 "solutions") 😉
G3S
Creator III
Creator III
Author

@Taoufiq_Zarra  Thank you.

 

If there are other fields in the 'Data' table should they be loaded in the 'output' table? 
in my question I only mentioned the fields relevant to my query.

arulsettu
Master III
Master III

You can try this as well

TempDate:

Load Max(RatesValidity) as Maxdate from table;

Let vmax = peek('Maxdate',0,'TempDate');

drop table TempDate;

 

// Now use this variable in your load statement where clause

 

load

POL,

Carrier,

Version,

RatesValidity,

TEU

from table_name where RatesValidity >='$(vmax)';

 

*Include the fields you want

Taoufiq_Zarra

@G3S 

YES

Regards,
Taoufiq ZARRA

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

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