admin 管理员组

文章数量: 1184232

I have the following list

  • Jon

  • James

  • Peter

  • Liz

  • Sabrina

  • James

  • Maria

  • Jon

  • Liz

  • Liz

  • Sarah

  • ...

I then want a list that shows me how many times each name occurs. Then it should give me a rank for each name, if a rank has ties, I want to re-number them alphabetically.

So the list should look like this:

(A) Name (B) How often (C) Rank #
Jon 2 3
James 2 2
Peter 1 5
Liz 3 1
Sabrina 1 6
Maria 1 4
Sarah 1 7

I have the following list

  • Jon

  • James

  • Peter

  • Liz

  • Sabrina

  • James

  • Maria

  • Jon

  • Liz

  • Liz

  • Sarah

  • ...

I then want a list that shows me how many times each name occurs. Then it should give me a rank for each name, if a rank has ties, I want to re-number them alphabetically.

So the list should look like this:

(A) Name (B) How often (C) Rank #
Jon 2 3
James 2 2
Peter 1 5
Liz 3 1
Sabrina 1 6
Maria 1 4
Sarah 1 7

And then in a seperate list I only want to show the top 5, sorted by their rank.

When I rank them from column B, I allways get duplicated ranks, for example with

=ARRAYFORMULA(IF(B2:B<>""; RANK(B2:B; B2:B; 0); ""))
Share Improve this question edited Jan 20 at 7:21 DarkBee 15.7k8 gold badges70 silver badges114 bronze badges asked Jan 20 at 3:56 Jana KemmerJana Kemmer 211 silver badge1 bronze badge 1
  • Give a try to the formula =RANK(B2,$B$2:$B$8,0)+(SUM(INDEX(--($B$2:B8=B2))))-1. – Harun24hr Commented Jan 20 at 4:23
Add a comment  | 

3 Answers 3

Reset to default 1

You may use the following formulas-

=XMATCH(C2,SORT($C$2:$C$8,1,FALSE))+COUNTIFS($C$2:C2,C2)-1
=RANK(C2,$C$2:$C$8,0)+(SUM(INDEX(--($C$2:C2=C2))))-1

Or all in one formula in cell G2. Adjust the formula as per need.

=LET(x,QUERY(A2:A,"select A, count(A) where A is not null group by A label count(A) ''"),
y,CHOOSECOLS(x,2),
z,MAP(y,SEQUENCE(ROWS(y)),LAMBDA(r,rw,RANK(r,y,0)+(SUM(INDEX(--(QUERY(y,"limit " &rw)=r))))-1)),HSTACK(x,z))

And to keep only top 5 values (from lowest to highest rank). Use QUERY() or SORTN() function.

=SORTN(LET(x,QUERY(A2:A,"select A, count(A) where A is not null group by A label count(A) ''"),
y,CHOOSECOLS(x,2),
z,MAP(y,SEQUENCE(ROWS(y)),LAMBDA(r,rw,RANK(r,y,0)+(SUM(INDEX(--(QUERY(y,"limit " &rw)=r))))-1)),HSTACK(x,z)),5,,3,1)

Output from above formula.

Names How Often Rank
Liz 3 1
James 2 2
Jon 2 3
Maria 1 4
Peter 1 5

Here's another solution:

={
  QUERY(A2:A,
    "SELECT Col1, COUNT(Col1)
     WHERE Col1 IS NOT NULL
     GROUP BY Col1
     ORDER BY COUNT(Col1) DESC
     LABEL COUNT(Col1)''"),
  SEQUENCE(COUNTUNIQUE(A2:A))
 }

To get just the top 5, you can use:

=QUERY(
  QUERY(A2:A,
    "SELECT Col1, COUNT(Col1)
     WHERE Col1 IS NOT NULL
     GROUP BY Col1
     ORDER BY COUNT(Col1) DESC
     LABEL COUNT(Col1)''"
  ),
  "SELECT Col1 
   LIMIT 5"
 )

Try this alternative formula using Filter, Unique, CountIf

=ARRAYFORMULA(Sort({FILTER(UNIQUE(A2:A), COUNTIF(A2:A, UNIQUE(A2:A)) <> 0, COUNTIF(A2:A, UNIQUE(A2:A)) <> 8),FILTER(COUNTIF(A2:A, UNIQUE(A2:A)), COUNTIF(A2:A, UNIQUE(A2:A)) <> 0, COUNTIF(A2:A, UNIQUE(A2:A)) <> 8),FILTER(RANK(COUNTIF(A2:A, UNIQUE(A2:A)), COUNTIF(A2:A, UNIQUE(A2:A)), 0) + COUNTIFS(COUNTIF(A2:A, UNIQUE(A2:A)), COUNTIF(A2:A, UNIQUE(A2:A)), UNIQUE(A2:A), "<"&UNIQUE(A2:A)), COUNTIF(A2:A, UNIQUE(A2:A)) <> 0, COUNTIF(A2:A, UNIQUE(A2:A)) <> 8)}, 3, TRUE))

Sample Output

(A) Name (B) How often (C) Rank #
James 1 1
Jon 1 2
Liz 1 3
Maria 1 4
Peter 1 5
Sabrina 1 6
Sarah 1 7

本文标签:

Error[2]: Invalid argument supplied for foreach(), File: /www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm, Line: 58
File: /www/wwwroot/roclinux.cn/tmp/route_read.php, Line: 205, include(/www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm)
File: /www/wwwroot/roclinux.cn/tmp/index.inc.php, Line: 129, include(/www/wwwroot/roclinux.cn/tmp/route_read.php)
File: /www/wwwroot/roclinux.cn/index.php, Line: 29, include(/www/wwwroot/roclinux.cn/tmp/index.inc.php)