Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

script to get the record related to min date for each type(non key field) using QV builtin functions

Hello All,

PFB th scenario.

Table 1
ObjectDateType
O1D11
O2D21
O3D32
Table 2
ArticleObject
AO1
AO2
BO1
BO3
Join
ArticleObjectDateType
AO1D11
AO2D21
BO1D11
BO3D32
Required
  result
ArticleObjectDateType
AO1D11
BO1D11
BO3D32

whenever an article has the same Type, the For each article, the Type with the minimum date is to be retained and the rest are to be excluded.

Could you please suggest how this can be achieved in script, without using a group by and by using QV functions.

Thanks!

12 Replies
anbu1984
Master III
Master III

Use Flag = 1 to retain the rows

T1:

LOAD Object ,Date#(Date,'DD/MM/YYYY') As Date ,Type INLINE [

    Object ,Date ,Type

    O1 , 01/01/2015, 1

    O1 , 15/01/2015, 1

    O3 , 06/01/2015, 2

];

NoConcatenate

T1_F:

Load *,If(Object <> Peek(Object) And Type <> Previous(Type),1,0) As Flag Resident T1 Order by Object,Type,Date;

Join

LOAD * INLINE [

    Article, Object

    A, O1

    A, O2

    B, O1

    B, O3

];

Drop Table T1;

Not applicable
Author

Hello Anbu,

Thanks for the reply

Could you modify your input set according to the question i have shared.

It should be O1, O2, O3

and not O1,O1,O3

When changed so, i am not gettting the expected result.

Appreciate ur help!

anbu1984
Master III
Master III

Try this

T1:

LOAD Object ,Date#(Date,'DD/MM/YYYY') As Date ,Type INLINE [

    Object ,Date ,Type

    O1 , 01/01/2015, 1

    O2 , 15/01/2015, 1

    O3 , 06/01/2015, 2

];

Join

LOAD * INLINE [

    Article, Object

    A, O1

    A, O2

    B, O1

    B, O3

];

NoConcatenate

T1_F:

Load *,If(Article <> Peek(Article),1,If(Type <> Previous(Type),1,0)) As Flag Resident T1 Order by Article,Type,Date;

Drop Table T1;