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: 
Not applicable

Using ApplyMap() to get largest value (when there are duplicates)

Hello,

I'm currently loading two tables.
The first table has some subset of keys.
The second table has a full set of keys with one or more dates associated with it.

I want to create a third table such that it has the subset of keys from table1 with the max(Date).
When I do an ApplyMap() it takes the min(Date) (or perhaps whichever value shows first). Is there a parameter within ApplyMap() I can use to take max(Date)?

Thanks!

Below is an example:

Table1:

A
1
3
5
6
8

Table2:

B
Date
11/3
15/3
26/22
39/21
42/25
47/31
52/11
55/21
56/11
66/12
611/15
77/29
82/5
89/15
912/13

What I want Table3 to look like:

Table3:

A
YAY
15/3
39/21
56/11
611/15
89/15

And... code that doesn't work (this takes min(Date)):


Table1:
LOAD * INLINE [
A
1
3
5
6
8
];

Table2:
LOAD * INLINE [
B, DATE
1, 1/3/2011
1, 5/23/2011
2, 6/21/2011
3, 9/21/2011
4, 2/25/2011
4, 7/31/2011
5, 2/11/2011
5, 5/21/2011
5, 6/11/2011
6, 6/12/2011
6, 11/12/2011
7, 7/29/2011
8, 2/5/2011
8, 9/15/2011
8, 12/13/2011
9, 1/23/2011
];

MAP_Date:
mapping load
B, DATE
resident Table2;

Table3:
load
A,
ApplyMap('MAP_Date', A, 0) as YAY
resident Table1;

1 Solution

Accepted Solutions
Clever_Anjos
Employee
Employee

Why don´t you use LEFT JOIN instead?

LEFT JOIN (Table1)
LOAD
B as A,
MAX(DATE) as MAXDATE
RESIDENT Table2
GROUP BY B;

View solution in original post

2 Replies
Clever_Anjos
Employee
Employee

Why don´t you use LEFT JOIN instead?

LEFT JOIN (Table1)
LOAD
B as A,
MAX(DATE) as MAXDATE
RESIDENT Table2
GROUP BY B;

johnw
Champion III
Champion III

Left join sounds good to me.  But if the map fits your situation better for whatever reason, build your map just like Clever Anjos built the join:

MAP_Date:
MAPPING LOAD
B, MAX(DATE) as MAXDATE
RESIDENT Table2
GROUP BY B;