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: 
joshm43
Contributor III
Contributor III

Using a calculated value to pull field name for highest value.

Hello -

I am trying to identify a field value based on the result of a calculation.

In the following example, I have four locations with varying numbers of incidents for each entry. 

LocationIncidents
West32.5
North24.9
South63.2
West22.5
East30.2
North57.8
South64.7
North4.7
West10.1
East59
South29.2

 

What I want  to do is to identify the location with the highest average number of incidents, the pull the value for that location.

I am able to use Max(), Aggr(), and Avg() to get the highest average number of incidents:

Max(Aggr(Avg(Incidents), Location))

But am then challenged to retrieve the Location value associated with it.

Thanks,

Mitch

One late addition.  My intent is to be able to use this expression in a Text object.

1 Solution

Accepted Solutions
Lisa_P
Employee
Employee

The FirstSortedValue() Function is what you need.
FirstSortedValue(Location, - Aggr(Avg(Incidents), Location))
The FirstSortedValue will select from the lowest, so the minus symbol then looks for the highest.

View solution in original post

2 Replies
Lisa_P
Employee
Employee

The FirstSortedValue() Function is what you need.
FirstSortedValue(Location, - Aggr(Avg(Incidents), Location))
The FirstSortedValue will select from the lowest, so the minus symbol then looks for the highest.
joshm43
Contributor III
Contributor III
Author

Thanks for the quick answer.  I tested and it works perfectly!  In looking at your example, I was not specifying the field correctly.  Best, Mitch