Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
palcham
Contributor
Contributor

Functions firstsortedvalue and aggr

Dear all, I have been battling with this problem for many days now and would like to ask for some help on how to solve.

 

I have a table of data which contains the costs of products depending on the date I bought them :

DateItemCost
01/01/2019A1
01/02/2019A2
01/03/2019A3
01/02/2019B6
01/05/2019B9
01/07/2019B3
01/04/2019C5
01/05/2019C7
01/06/2019C5

 

 

I am trying to create a table to show the costs of the products showing the price of the first buy and the last buy of each one of them:   

 

ItemInitial CostFinal Cost
A13
B63
C55

 

I am trying to use this two functions ( FirstSortedValue and aggr) but it won´t work for me, I would need some help.

This is an example of how I am using the functions:

FirstSortedValue( distinct Cost, aggr(Max(  Cost), Item, Date),1) and FirstSortedValue( distinct Cost, -aggr(Max(  Cost), Item, Date),1)

But it won´t give me the first and last value, It gives me tha maximun and minimun values.

Thank you very much in advance, I hope you can give me some assistance with this.

 

Labels (1)
1 Reply
trdandamudi
Master II
Master II

One way you can do this is as below:

In a straight chart:

Dimension:

Item

Expression: (Initial_Cost)

=FirstSortedValue(Cost, Date)

Expression: (Final_Cost)

=FirstSortedValue(Cost, -Date)

 

Also you can do this in the script. Please take a look at the attached file and you have both solutions. Hope this helps.