Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to get value from the latest date

Hello - I'm new user. I was looking for  a solution in other discussions but with poor results. I have one table with average cost history.

Item numberTrans dateTranse timeNew avg cost
A20120620132632172
A20120621135206172
A20120627101107175
B20120620132632111
B20120621135207111
B20120627101107110
C20120620132632305
C20120621135207305
C20120627101107

309

For each item number I want take 'New avg cost' value for the latest date (and if there are few rows with same item and date - latest transaction time). For this example result would be:

A - 175

B - 110

C - 309

I have tried aggr functions but as a result I have max value.

Thanks in advance.

Best regards from Poland

Paweł

1 Solution

Accepted Solutions
Not applicable
Author

Can't you just concatenate your transaction date and time to get a unique value? Are there so many transactions that you will get a substantial number of transactions occuring on the same second?

I had this problem with our contact management system (which only has standard output yy/mm/dd hh:mm) until I found that there was a way to extract the actual seconds value from the record ID. I used a "LOAD" statement to create a new field I called "FullTime" from the combination of Date, Time, and Seconds, and then was able to use FirstSortedValue(FullTime) to find distinct entries.

View solution in original post

4 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Use the firstsortedvalue function: firstsortedvalue([New avg cost], -[Trans date])

Note, this only works if there is only one record (per Item number) with the maximum date. In your sample data this is the case, so it will work on that data.

edit: I see that Transe time should also be considered. Try firstsortedvalue([New avg cost], -[Trans date]&[Transe time])


talk is cheap, supply exceeds demand
Not applicable
Author

Thanks for fast response. Unfortunatelly there are many records with same (max) date (per item number).

Not applicable
Author

Can't you just concatenate your transaction date and time to get a unique value? Are there so many transactions that you will get a substantial number of transactions occuring on the same second?

I had this problem with our contact management system (which only has standard output yy/mm/dd hh:mm) until I found that there was a way to extract the actual seconds value from the record ID. I used a "LOAD" statement to create a new field I called "FullTime" from the combination of Date, Time, and Seconds, and then was able to use FirstSortedValue(FullTime) to find distinct entries.

Not applicable
Author

Finally I have managed to do this with your help guys!!! Thanks a lot. So in a script there is:

Trans_date&if(LEN(Trans_time)<6,'0')&Trans_time AS FullTime

And in table:

=firstsortedvalue(New avg cost, -FullTime)

Thank you one more time.