Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
mhassinger
Creator
Creator

Getting records with only max date

So I've got data that looks something like:

Key1Key2Created DateRecord Type
111/1/2018A
211/2/2018B
321/1/2018B
421/2/2018D

I want to get the records that have the max date, grouped by key 2, like:

Key1Key2Created DateRecord Type
211/2/2018B
421/2/2018D

It's easy enough to do

Load Max(Crated Date), Key2

Group by Key2

But that doesn't get me Key1 and Record Type.

5 Replies
ankit777
Specialist
Specialist

Hi

After getting max created date and key2, you can join remaining columns from original table based on combination of key2 and created date.

tresesco
MVP
MVP

Try like:

Load

          Max([Created Date]) as [Created Date],

          Key2,

          FirstSortedValue(Key1, - [Created Date]) as Key1,

         FirstSortedValue([Record Type] ,- [Created Date]) as [Record Type]

Group by Key2;

MindaugasBacius
Partner - Specialist III
Partner - Specialist III

What about:


Load

    Max(Created Date) as [Created Date],

    Max(Key1) as Key1,

    Key2

Group by Key2

;

MarcoWedel

Hi,

one solution might be:

QlikCommunity_Thread_309017_Pic1.JPG

table1:

LOAD * FROM [https://community.qlik.com/thread/309017] (html, codepage is 1252, embedded labels, table is @1);

Right Join

LOAD Key2,

    Max([Created Date]) as [Created Date]

Resident table1

Group By Key2;

hope this helps

regards

Marco

MarcoWedel

another solution would be:

table1:

LOAD * FROM [https://community.qlik.com/thread/309017] (html, codepage is 1252, embedded labels, table is @1);

table2:

LOAD *,

    Key2 as Key2Temp

Resident table1

Where not Exists (Key2Temp, Key2)

Order By [Created Date] desc;

DROP Table table1;

DROP Field Key2Temp;

hope this might help as well

regards

Marco