Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Get top three names

Hi all,

I have to get top 3 names from a field, but first I have to filter the dataset to max(count) of field A and than max(count) Field B. From this filtered dataset IK have to get the top 3 names from Name field. I am using the below expression to filter the data and get the top 3 names and their count.

The issue I am facing is that this expression is returning me all the names and their count. But I am not able to restrict it to the top three names and count

=Concat({<
[field A] = {"=rank(Count([field A]),4)=1"},
[Field B]={"=rank(count([Field B]))=1"}>} 
Aggr(Only( [name]) & ' ('&Count([name])&')', [name], [name],[field A]))

6 Replies
sunny_talwar

Difficult to say much without taking a peek at your data? Would you be able to provide some raw data?

marcus_sommer

I think you need to apply the rank-condition within the inner aggregation: Set Analysis in the Aggr function.

- Marcus

ramasaisaksoft

Hi Fayez,

Is there any chance to you (Dimension Limit) for top 3 ,can u think that way?

i know you can't write set analysis there but you can control .

Anonymous
Not applicable
Author

Hi

Is it like this ?

=if(Aggr(Rank(COUNT(field A)),name)<=3, 'TOP3NAMES:$(=Concat(DISTINCT name, ', '))', 'Others')

=if(Aggr(Rank(COUNT(field B)),name)<=3, 'TOP3NAMES:$(=Concat(DISTINCT name, ', '))', 'Others')

   

//Edited

FYI

I think the above expression works only if you select at least 4 or 5 values ....

Anonymous
Not applicable
Author

No, I am putting the result in text box

Anonymous
Not applicable
Author

Thanks Sunny,

I have pasted the dummy data below.

First I have to find out which string or value has been used max no of times. In this case it will be Net Sales. So I have to filter this data to Net Sales. After this, in the filtered dataset I have to find out  which value has been used max no of times in Field A. In this case it will be General Industries. So I will have to filter the filtered dataset further to General Industries. Now my data set will have General Industries in Field A , Net Sales In Field B, and

these

   

Reagle,Daniel K.
Wickline,Samuel Joel
Wickline,Samuel Joel
Wickline,Samuel Joel
Planert,Tina M
Reagle,Daniel K.
Wells,Kristen Michelle

in the name field.

I have to get the top 3 names in this field along with their count. Like Wickline,Samuel Joel (3),Reagle,Daniel K.(2),Planert,Tina M(1).

I will ignore Wells,Kristen Michelle, as I have got Planert,Tina M as the third name. So effectly it doesn't matter which 1 I take, I just have to limit the overall names to 3 persons.

Hope I could explain it to you.

So when I use below expression it does not return me the correct results because Name is ranked in the complete data set rather than the filtered datset.

   

NameRank
Sullivan,Steven P2
Sullivan,Steven P2
Sullivan,Steven P2
Reagle,Daniel K.1
Reagle,Daniel K.1
Wickline,Samuel Joel3
Wickline,Samuel Joel3
Wickline,Samuel Joel3
Planert,Tina M4
Planert,Tina M4
Reagle,Daniel K.1
Reagle,Daniel K.1
Reagle,Daniel K.1
Reagle,Daniel K.1
Reagle,Daniel K.1
Wickline,Samuel Joel3
Valentino  Pence,Geoffrey Brett5
Valentino  Pence,Geoffrey Brett5
Wells,Kristen Michelle6

=Concat({<
[field A] = {"=rank(Count([field A]),4)=1"},
[Field B]={"=rank(count([Field B]))=1"}>}  ,[Name]={"=rank(count(name))<=3"}>}
Aggr(Only( [name]) & ' ('&Count([name])&')', [name], [name],[field A]))

   

Field AField BName
     Generic TemplateNet Sales Sullivan,Steven P
     Generic TemplateNet Sales Sullivan,Steven P
     Generic TemplateNet Sales Sullivan,Steven P
     Generic TemplateNet Sales Reagle,Daniel K.
     General IndustriesNet Sales Reagle,Daniel K.
     General IndustriesNet Sales Wickline,Samuel Joel
     General IndustriesNet Sales Wickline,Samuel Joel
     General IndustriesNet Sales Wickline,Samuel Joel
     General IndustriesNet Sales Planert,Tina M
       Middle MarketInterestPlanert,Tina M
       Middle MarketInterestReagle,Daniel K.
       Middle MarketInterestReagle,Daniel K.
       Middle MarketInterestReagle,Daniel K.
       Middle MarketInterestReagle,Daniel K.
       Middle MarketInterestReagle,Daniel K.
       Middle MarketInterestWickline,Samuel Joel
       Middle MarketInterestValentino Pence,Geoffrey Brett
     General IndustriesNet Sales Reagle,Daniel K.
     General IndustriesNet Sales Wells,Kristen Michelle