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: 
Not applicable

Getting data for the latest event in a project

Hi all.

Qlikview's behavior is baffling me, and I'm wondering if I can get some help.

I have a workbook that contains data for a number of different projects. Each project is associated with a number of events, and each event has a date and a value associated with it. I'm interested in getting a table that displays for each project the value associated with the latest event associated with the project. So for example if we had the following data

ProjectEventDateValue
AeA12014-01-025
AeA22014-01-066
AeA32014-01-107
BeB12014-01-018
BeB22014-01-079
CeC12014-01-0310
CeC22014-01-0411

I'd like to create a table that looks like this:

ProjectLatest dateLatest value
A2014-01-107
B2014-01-079
C2014-01-0411

Every project has at least one event. All the values are positive, and no two events occur on the same date for the same project.


For this table, Project is the dimension, and Latest date is just max([Event Date]). But I'm having trouble with Latest value. My attempts are somewhere in this realm:

only( if ([Event Date] = aggr(max([Event Date]), [Project]), [Event Value]) )

This actually produces the correct answer for some of the projects, but there are other projects that get no value in the table at all. Further investigation shows that for some -- but not all -- of the projects [Event Date] = aggr(max([Event Date]), [Project]) evaluates to false for every row. I have been unable to determine a commonality among the projects that act like this. I cannot understand this behavior; surely some date must equal the max of the date. So perhaps I am just misunderstanding the semantics of the aggr function.

Any ideas? Any pointers would be much appreciated.

Thanks!

1 Solution

Accepted Solutions
Not applicable
Author

I would rather work in the script for this one creating a flag via resident load and a group by?

View solution in original post

5 Replies
Not applicable
Author

And of course if there's a simpler or better way to accomplish this, I would love to hear it.

Thanks again!

Not applicable
Author

I would rather work in the script for this one creating a flag via resident load and a group by?

maxgro
MVP
MVP

Hi

try with

dimension = Project

expression = FirstSortedValue(Date, -Date)

expression = FirstSortedValue(Value, -Date)

Please see attachment

Regards

Not applicable
Author

This does work for my stripped down example, but my example (evidently) doesn't capture all the complexity in my workbook; adapting this answer to my workbook gives a "-" value indicating an error somewhere that I can't determine. In the end I solved this in my load script. Thanks for the suggestion, though -- I'll keep this (very helpful!) function in mind!

Not applicable
Author

Yes, that did it. Thank you! It seems that one of the subtleties of Qlikview development is when to munge data in the load scripts vs in Qlikview itself. Thanks again!