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: 
psk180590
Creator III
Creator III

Select values against the first(Min) Date

Hello All,

I have the following data:

Article CodeDateCost
101.01.20123
101.02.20125
101.06.201215
201.01.20126
301.01.201230
301.09.201223
101.01.201310
101.07.201312

My Date field is in 'DD.MM.YYYY' Format.

I would like to have the Cost of each Article against the Min of Date.

My expected result is:

Article CodeYearCost
120123
220126
3201230
1201310

Tried with First() Function but, somehow the Years keep repeating.

TIA!!

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Try like:

SET DateFormat='DD.MM.YYYY';

t1:

Load * Inline [


Article Code, Date, Cost

1, 01.01.2012, 3

1, 01.02.2012, 5

1, 01.06.2012, 15

2, 01.01.2012, 6

3, 01.01.2012, 30

3, 01.09.2012, 23

1, 01.01.2013, 10

1, 01.07.2013, 12]

;


t2:

Load

Year(Date) as Year,

*

Resident t1;


t3:

Load

Year,

"Article Code",

FirstSortedValue(Cost, Date) as Cots

Resident t2 Group By Year,"Article Code";


Drop table t1, t2;

Capture.JPG

View solution in original post

4 Replies
Anil_Babu_Samineni

Script or Front end?

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
psk180590
Creator III
Creator III
Author

Script

Anil_Babu_Samineni

Try this?

SET DateFormat='DD.MM.YYYY';

Table:

LOAD *, Year(Date) as Year Inline [

Article Code, Date, Cost

1, 01.01.2012, 3

1, 01.02.2012, 5

1, 01.06.2012, 15

2, 01.01.2012, 6

3, 01.01.2012, 30

3, 01.09.2012, 23

1, 01.01.2013, 10

1, 01.07.2013, 12

];

Right Join(Table)

LOAD Min(Date) as Date, Year, [Article Code] Resident Table Group By Year, [Article Code];

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
tresesco
MVP
MVP

Try like:

SET DateFormat='DD.MM.YYYY';

t1:

Load * Inline [


Article Code, Date, Cost

1, 01.01.2012, 3

1, 01.02.2012, 5

1, 01.06.2012, 15

2, 01.01.2012, 6

3, 01.01.2012, 30

3, 01.09.2012, 23

1, 01.01.2013, 10

1, 01.07.2013, 12]

;


t2:

Load

Year(Date) as Year,

*

Resident t1;


t3:

Load

Year,

"Article Code",

FirstSortedValue(Cost, Date) as Cots

Resident t2 Group By Year,"Article Code";


Drop table t1, t2;

Capture.JPG