Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Question about the record selection

Hi guys,

I have a question which needs your help...I have a table below which contains date A and date B. I want to get my final table which only contains the closest A to B and A<B. How to achieve that?

Original table:

IDdate Adate B
112/31/20129/30/2011
13/31/20099/30/2011
16/30/20109/30/2011
26/30/20114/30/2010
25/31/20124/30/2010
33/31/20083/31/2009
35/31/20103/31/2009
37/31/20123/31/2009

Final table:

IDdate Adate B
16/30/20109/30/2011
33/31/20083/31/2009

Thanks!

7 Replies
anbu1984
Master III
Master III

How do you define close? Is it less than a year?

pgrenier
Partner - Creator III
Partner - Creator III

Hello Kitty,

I believe you can achieve your goal with this statement

FinalTable:

LOAD ID, Max([date A]), Max([date B]

Resident OriginalTable

Where [date A] < [date B];

Regards,

Philippe

Not applicable
Author

Hi anbu,

By saying "close" I mean the latest date A where A<B, it's not have to be less than one year.

anbu1984
Master III
Master III

Then use this expression

If(DtB - DtA>0 ,DtB - DtA)

its_anandrjs

Can you explain more in details about near values for date and what is mean for closest A to B and A<B.

Not applicable
Author

Use this script

 

Test2:

Load * Inline [
ID, date A, date B
1, 12/31/2012, 9/30/2011
1, 3/31/2009, 9/30/2011
1, 6/30/2010, 9/30/2011
2, 6/30/2011, 4/30/2010
2, 5/31/2012, 4/30/2010
3, 3/31/2008, 3/31/2009
3, 5/31/2010, 3/31/2009
3, 7/31/2012, 3/31/2009
]
;

FinalTable:
NoConcatenate
LOAD *
Resident Test2
Where [date A] < [date B];

Drop Table Test2;

Hope it helps you..

maxgro
MVP
MVP

SCRIPT


SET DateFormat='MM/DD/YYYY';

DIRECTORY;

source:

LOAD

  ID,

    [date A] as A,

    [date B] as B,

    [date B] - [date A] as DIFF

FROM

[http://community.qlik.com/thread/114995]

(html, codepage is 1252, embedded labels, table is @1)

Where [date B] - [date A] >= 365;  

table:

NoConcatenate

load

  *

Resident source

Where (Peek(ID) <> ID)

order by ID, DIFF;

DROP Table source;

1.png