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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
somacdc
Contributor III
Contributor III

Max date less than and equal to another table date

I want to calculate the max date of following Table1 which is less than and equal to another table (Table2) date.

Table1:

IDF_NUMBERNAV_1
201134/3/2032
201159/3/2032
2011512/3/2032

 

Table2:

IDF_NUMBERNAV_2
201139/3/2032
2011310/3/2032
2011311/3/2032
2011312/3/2032
201159/3/2032
2011510/3/2032
2011511/3/2032
2011512/3/2032

 

and this is what i want it to return.

IDF_NUMBERNAV
201134/3/2032
201134/3/2032
201134/3/2032
201134/3/2032
201159/3/2032
201159/3/2032
201159/3/2032
2011512/3/2032

 

I'm using mapping but it doesn't work with F_NUMBER=3

 

2 Replies
Rodj
Partner - Creator III
Partner - Creator III

I tried the following, which I think matches what you've asked for in your question but doesn't match your example result. I can't work out what you are really asking for as for F_NUMBER = 5 I can't see any logic as to how you've determined the answer. You've asked for the max date from table 1, which would be 12/3, yet you've used 9/3 in all but one result record. There's no uniqueness in the other records with which to determine any other matching than what I've done.

[temp1]:
LOAD * INLINE
[
ID,F_NUMBER,NAV_1
2011,3,4/3/2032
2011,5,9/3/2032
2011,5,12/3/2032
];

[temp2]:
LOAD * INLINE
[
ID,F_NUMBER,NAV_2
2011,3,9/3/2032
2011,3,10/3/2032
2011,3,11/3/2032
2011,3,12/3/2032
2011,5,9/3/2032
2011,5,10/3/2032
2011,5,11/3/2032
2011,5,12/3/2032
];


Maxtemp:
NoConcatenate
Load Max(NAV_1) as maxNav1,
ID,
[F_NUMBER]
resident temp1
group By ID, [F_NUMBER];
Join
load ID,
[F_NUMBER],
[NAV_2]
Resident temp2;

Final:
NoConcatenate
Load
ID,
[F_NUMBER],
if(maxNav1 <= NAV_2, Date(maxNav1, 'D/M/YYYY'), NAV_2) as NAV
Resident Maxtemp;

drop tables temp1, temp2, Maxtemp;

somacdc
Contributor III
Contributor III
Author

Thanks for reply.

Actually I'm asking for F_NUMBER = 5 from table 1 which have (suppose we have 8/3 also), 9/3 and 12/3

but from table 2 which have 9/3, 10/3,  11/3 and 12/3

so logic is that date of table 1 and table 2 :

9/3 is equal to 9/3 then result is 9/3,

8/3 and 9/3 is not equal to 10/3 then check less than 10/3  so,Max of both (8/3 and 9/3) and the result is 9/3

so on.

following is the oracle query as Function used for your reference

SELECT MAX(NAV_1)
FROM table1
WHERE NAV_1 <= 10/3
AND ID = 2011
AND F_NUMBER = 5