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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
stevelord
Specialist
Specialist

neither firstsortedvalue nor max(testdate) getting desired result

Hi I've tried these two formulas on a pivot table and get 'Expression Ok' from Qlikview, but my testdate column is picking the february test when it has a choice between february and march 2012 tests.  I have a separate tablebox with userid, testdate, and testvalues with all dates/values showing to compare my pivot table to.  Strangely, my pivot table doesn't seem to change whether I have the - or not in firstsortedvalue, and whether I have max(TestDate) or min(TestDate)  Any idea what could cause this?  Whatever the data source, it seems to me that toggling the - sign or toggling min/max on TestDate should make the table change.. (Yes, I pushed apply and okay. )

Dimensions: ClientName(left out of below view), UserId (ficticious), TestDate

Expressions tried all produced the tables shown below::

if([rbTotal Cholesterol],Count(aggr(firstsortedvalue([rbTotal Cholesterol],-1*TestDate), UserId)))

if([rbTotal Cholesterol],Count(aggr(firstsortedvalue([rbTotal Cholesterol],TestDate), UserId)))

if([rbTotal Cholesterol],Count(aggr(max(TestDate), UserId)))

if([rbTotal Cholesterol],Count(aggr(min(TestDate), UserId)))

The if might not be needed on firstsortedvalue- it just sort of carried over from when I tried max(TestDate)

PivotTable
UserIdTestDate[rbTotal Cholesterol]OptimalBorderlineOut of Range
7022/14/2012 1
7082/14/2012 1
7112/14/2012 1
7162/14/2012 1
7182/14/2012 1
7192/14/2012 1
7202/14/2012 1

Tablebox

UserIdTestDate[rbTotal Cholesterol]
7022/14/2012Borderline
7022/16/2012Out of Range
7023/15/2012Out of Range
7082/14/2012Out of Range
7083/15/2012Borderline
7112/14/2012Out of Range
7113/15/2012Optimal
7162/14/2012Out of Range
7163/15/2012Optimal
7182/14/2012Optimal
7183/5/2012Optimal
7183/15/2012Optimal
7192/14/2012Out of Range
7193/15/2012Out of Range
7202/14/2012Out of Range
7203/15/2012Optimal

Note: Total Cholesterol field was created by a SUM(if(TestName='Total Cholesterol',TestValue)) as [Total Cholesterol] in a table grouped by Client, UserId, Date(Floor(TestDate)), and Year(TestDate).  The [rbTotal Cholesterol] was part of a subsequent resident load for if([Total Cholesterol]<200, dual('Optimal','Optimal'),.... etc as [rbTotal Cholesterol]  The original qvd file had columns UserId, TestName, TestValue, TestDate.  I worried about dates losing their links to the tests, but the tablebox looks okay in that regard and I only have one TestDate field available....

1 Solution

Accepted Solutions
stevelord
Specialist
Specialist
Author

Alright! I figured it out while complaining to my boss over IM. My aggr statement was just missing a couple of related fields needed for its grouping/group by framework.  Table didn't change until the last field of the group by was snapped into place.

So it was blahblahblah, Count(Aggr(max/firstsorted(whateverthing), UserId, Source, TestYear)

So I was just short on listing fields to group it by for the aggr function.  And if you have a table that doesnt change when you switch between min/max or +/-, you can check and add things to your aggr fields and save alot of money by switching to gecko.

PS> I spent another half hour experimenting to confirm this.  Table goes back to ignoring me when I take one of the underlined aggr fields back out and back to correct when I put the fields back in.

View solution in original post

1 Reply
stevelord
Specialist
Specialist
Author

Alright! I figured it out while complaining to my boss over IM. My aggr statement was just missing a couple of related fields needed for its grouping/group by framework.  Table didn't change until the last field of the group by was snapped into place.

So it was blahblahblah, Count(Aggr(max/firstsorted(whateverthing), UserId, Source, TestYear)

So I was just short on listing fields to group it by for the aggr function.  And if you have a table that doesnt change when you switch between min/max or +/-, you can check and add things to your aggr fields and save alot of money by switching to gecko.

PS> I spent another half hour experimenting to confirm this.  Table goes back to ignoring me when I take one of the underlined aggr fields back out and back to correct when I put the fields back in.