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: 
kdsonntag
Contributor
Contributor

FirstSortedValue returns Null

I am having trouble getting the desired output. I need an expression that gives me Score on most recent Date for each Client.

Sample

Client               Score               Date

Aaa                    25                    1/1/18

Aaa                    24                    5/1/18

Bbb                    24                    5/1/18

Bbb                    20                    2/1/18

Should return

Aaa                    24                    5/1/18

Bbb                    24                    5/1/18

If I don't use DISTINCT, get NULL

If I DO use DISTINCT, only get Aaa record, not Bbb.

What I'm currently using: FirstSortedValue(Score, -Date) or FirstSortedValue(DISTINCT Score, -Date)

8 Replies
sunny_talwar

Are you using Client as dimension? If you are... then this should not be a problem... if you are using this in a KPI object... try this

Sum(Aggr(FirstSortedValue(Score, -Date), Client))

kdsonntag
Contributor
Contributor
Author

Yes, Client as Dimension and used in KPI Object. 

Here's my expression: =Sum(Aggr(FirstSortedValue([Score],-[Date]), [Client])

Returns nothing.

sunny_talwar

You have a missing parenthesis at the end... is that a typo?

=Sum(Aggr(FirstSortedValue([Score],-[Date]), [Client]))

kdsonntag
Contributor
Contributor
Author

Yes, typo. Sorry about that.

sunny_talwar

Don't see any issue with this expression

Capture.PNG

kdsonntag
Contributor
Contributor
Author

Now I get all zero.

Aaa               0

Bbb               0

Here is expression with actual fields. Sorry, do not know how to export Qlik file. 

=Sum(Aggr(FirstSortedValue([PHQ9.Total Score],-[PHQ9.Assessment Date]),[PHQ9.Client Name]))

sunny_talwar

Unless you are able to share more information, I won't know what you have.

kdsonntag
Contributor
Contributor
Author

Thank you for trying to help. I have contacted the developer of our application for additional support and will post again when I have more info.