Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
reivax31
Partner - Creator III
Partner - Creator III

Find a unique max date

Hi Qlikers,

I have a table and based on several conditions I want to find a unique date for each ID.

The table is:

IDNUMNAMEDATE
110John01/03/2016
120Mike12/03/2016
130Tom14/03/2016
210John04/03/2016
220Tom10/03/2016
230Mike10/03/2016
240David06/03/2016

So basicaly the first think to do is to find the max DATE for each ID. For some ID you can have several lines with the same max DATE. In this case we look for the max NUM.

The expected result is:

IDNUMNAMEDATE
130Tom14/03/2016
230Mike10/03/2016

I tried a few things with GROUP BY, but the reultisn't there yet.

Thanks for your help

15 Replies
sunny_talwar

I have not done performance testing, but if you are comparing it to flag in script? I doubt that this will be better. But comparing it to another FirstSortedValue based on a single field, I don't think this would be so bad.

reivax31
Partner - Creator III
Partner - Creator III
Author

Hi Sunny,

Thanks again for your help. It worked perfectly !!

Xavier

reivax31
Partner - Creator III
Partner - Creator III
Author

Hi,

Maybe one last question, how can I create based on the same table a new dimmension with all my NAME's?

Table is

IDNUMNAMEDATE
110John01/03/2016
120Mike12/03/2016
130Tom14/03/2016
210John04/03/2016
220Mike10/03/2016
230Tom10/03/2016
240David10/03/2016

Result is:

 

IDNUMNAMEDATENEW DIMENSION
130Tom14/03/2016John/Mike/Tom
240David10/03/2016John/Mike/Tom/David

Thanks for your help

sunny_talwar

This may be:

Table:

LOAD * INLINE [

    ID, NUM, NAME, DATE

    1, 10, John, 01/03/2016

    1, 20, Mike, 12/03/2016

    1, 30, Tom, 14/03/2016

    2, 10, John, 04/03/2016

    2, 20, Mike, 10/03/2016

    2, 30, Tom, 10/03/2016

    2, 40, David, 10/03/2016

];

Left Join (Table)

LOAD ID,

  Concat(NAME, '/') as [NEW DIMENSION]

Resident Table

Group By ID;

Right Join(Table)

LOAD ID,

  Max(DATE) as DATE

Resident Table

Group By ID;

Right Join (Table)

LOAD ID,

  Max(NUM) as NUM

Resident Table

Group By ID;


Capture.PNG

Saravanan_Desingh

One more version..

Data:

Load ID, Max(NUM) As NUM,

  FirstSortedValue(NAME,-NUM) As NAME,

  FirstSortedValue(DATE,-NUM) As DATE,

     Concat(NAME, '/') as [NEW DIMENSION]

Group By ID

;

LOAD * INLINE [

    ID, NUM, NAME, DATE

    1, 10, John, 01/03/2016

    1, 20, Mike, 12/03/2016

    1, 30, Tom, 14/03/2016

    2, 10, John, 04/03/2016

    2, 20, Mike, 10/03/2016

    2, 30, Tom, 10/03/2016

    2, 40, David, 10/03/2016

]

;

reivax31
Partner - Creator III
Partner - Creator III
Author

Hi Sunny,

Once again it worked! thanks for you help