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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
maxattar
Partner - Contributor II
Partner - Contributor II

First sorted value with aggr

Hi, 

I am trying to get the value glf_cod corresponding to the highest count of lic_cod for each glf_cod.

I always get a null result when trying the following : 

FirstSortedValue(DISTINCT glf_cod,-Aggr(count(lic_cod),glf_cod))

I have tried with and without Distinct and there is no tie for the first value. 

Does anyone have an idea of what I seem to be doing wrong please ?

Labels (1)
4 Replies
BrunPierre
Partner - Master II
Partner - Master II

It may be this

=FirstSortedValue(DISTINCT glf_cod,-Aggr(Count(lic_cod ),glf_cod),1)

maxattar
Partner - Contributor II
Partner - Contributor II
Author

Hi Peter, 

Thanks for the answer but it still does not work : 

maxattar_1-1663257807830.png

 

 

BrunPierre
Partner - Master II
Partner - Master II

=Max(AGGR(Count(DISTINCT glf_cod ),lic_cod ))

maxattar
Partner - Contributor II
Partner - Contributor II
Author

Hi Pierre, thanks for your help but this returns the lic_cod with the most glf_cod associated with it.

I'm looking for the glf_cod where there are the most lic_cod (kind of the other way aroung from what you proposed). 

Max(AGGR(Count(DISTINCT lic_cod ),glf_cod )) would give me the highest count of lic_cod for the right glf_cod but I'm looking for the glf_cod, NOT the count associated with. FirstSortedValue would solve my problem but it keeps returning Null for a reason I don't get.