Combining Rank and Unique

alibini

New Member
Joined
Mar 15, 2020
Messages
30
Office Version
  1. 365
Platform
  1. Windows
Is there a way I can combine Rank and Unique to give me ranking of unique values from a column.

Tried this formula:

=RANK(U9,UNIQUE(FILTER($U$9:$U$18,U9:U18>0)))

but RANK doesn't seem to accept Unique as the range.
Thanks.

1720893008320.png
 
Book1
ABCD
1absolute
2100010002
350045500451
410004554
54555003
60
7500
80
90
10500
Sheet1
Cell Formulas
RangeFormula
C2:D5C2=LET(z,A2:A10,r,UNIQUE(FILTER(z,z>0)),HSTACK(r,MATCH(r,SORT(r,,-1),0)))
Dynamic array formulas.
 
Upvote 0
How about
Excel Formula:
=LET(f,UNIQUE(FILTER(U9:U18,U9:U18>0)),XMATCH(U9,SORT(f,,-1)))
 
Upvote 0
Another:

Excel Formula:
=SUM(--(U9<UNIQUE(FILTER($U$9:$U$18,$U$9:$U$18<>0))))+1

Just FYI, RANK requires the second parameter to be a range, not an array. That's why it didn't work. Also, your profile shows you use Excel 2016, which doesn't have UNIQUE or FILTER. You might wish to update your profile.
 
Upvote 0
Another:

Excel Formula:
=SUM(--(U9<UNIQUE(FILTER($U$9:$U$18,$U$9:$U$18<>0))))+1

Just FYI, RANK requires the second parameter to be a range, not an array. That's why it didn't work. Also, your profile shows you use Excel 2016, which doesn't have UNIQUE or FILTER. You might wish to update your profile.
Thanks for the solution and profile updated.
 
Upvote 0
Another:

Excel Formula:
=SUM(--(U9<UNIQUE(FILTER($U$9:$U$18,$U$9:$U$18<>0))))+1

Just FYI, RANK requires the second parameter to be a range, not an array. That's why it didn't work. Also, your profile shows you use Excel 2016, which doesn't have UNIQUE or FILTER. You might wish to update your profile.
Hi, just looking back on this solution, which works great for me. I was wondering since I apply this formula to a very large data set - approx 80,000 rows..... Is there a faster solution, possibly by doing the calculation in vba rather than with actual formula?

Thanks
 
Upvote 0
I apply this formula to a very large data set - approx 80,000 rows..... Is there a faster solution, possibly by doing the calculation in vba rather than with actual formula?
My test was with nearly 8,000 rows only but these approximate calculation times on my (old) machine may give you something to consider.
From your attempted formula in post 1 I wasn't certain what you were trying to do with zero values or whether you may have blank cells in the range. For the moment I have assumed no blanks and 0 values to be ranked at the bottom like Eric's formula does.

Formula from post 4 (adjusted to row 8,000)
About 30 seconds

Formula from post 3 (adjusted to row 8,000)
About 30 seconds

This formula (only needs to be placed in the top cell and not copied down)
0.04 seconds
Excel Formula:
=MATCH(U9:U8000,SORT(UNIQUE(U9:U8000),,-1),0)

The vba code below (which places the results in Y9 and below but can be varied in the second last line of the code)
0.09 seconds

VBA Code:
Sub Rank_Unique()
  Dim SL As Object
  Dim a As Variant, b As Variant
  Dim i As Long, SLC As Long

  Set SL = CreateObject("System.Collections.Sortedlist")
  a = Range("U9", Range("U" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 1)
  For i = 1 To UBound(a)
    If Not SL.Contains(a(i, 1)) Then SL.Add a(i, 1), 1
  Next i
  SLC = SL.Count
  For i = 1 To UBound(a)
    b(i, 1) = SLC - SL.IndexOfKey(a(i, 1))
  Next i
  Range("Y9").Resize(UBound(b)).Value = b
End Sub
 
Upvote 0
My test was with nearly 8,000 rows only but these approximate calculation times on my (old) machine may give you something to consider.
From your attempted formula in post 1 I wasn't certain what you were trying to do with zero values or whether you may have blank cells in the range. For the moment I have assumed no blanks and 0 values to be ranked at the bottom like Eric's formula does.

Formula from post 4 (adjusted to row 8,000)
About 30 seconds

Formula from post 3 (adjusted to row 8,000)
About 30 seconds

This formula (only needs to be placed in the top cell and not copied down)
0.04 seconds
Excel Formula:
=MATCH(U9:U8000,SORT(UNIQUE(U9:U8000),,-1),0)

The vba code below (which places the results in Y9 and below but can be varied in the second last line of the code)
0.09 seconds

VBA Code:
Sub Rank_Unique()
  Dim SL As Object
  Dim a As Variant, b As Variant
  Dim i As Long, SLC As Long

  Set SL = CreateObject("System.Collections.Sortedlist")
  a = Range("U9", Range("U" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 1)
  For i = 1 To UBound(a)
    If Not SL.Contains(a(i, 1)) Then SL.Add a(i, 1), 1
  Next i
  SLC = SL.Count
  For i = 1 To UBound(a)
    b(i, 1) = SLC - SL.IndexOfKey(a(i, 1))
  Next i
  Range("Y9").Resize(UBound(b)).Value = b
End Sub
Thanks Steve, I apologise but I think I was not explicit enough in what I'm trying to do.

I am trying to rank rows, based on a value in a column, where values in other columns are unique.

In the below table for example, I want to rank the Value (without duplicates) where the Identifier AND Date are the same. I have manually added the desired result for example. As mentioned my challenge is a large data set.

Currently I am using something like this:

=SUM(--(c3<UNIQUE(FILTER(Value_Range,(Identifier=A2)*(Date = B2)))))+1


IdentifierDateValueDesired Result
11-May1.51
11-May1.51
11-May1.62
11-May1.73
15-Jun1.83
15-Jun1.83
15-Jun1.62
15-Jun1.62
15-Jun1.94
15-Jun1.51
23-Nov1.51
23-Nov1.51
23-Nov1.62
23-Nov1.73
25-Jun1.84
25-Jun1.84
25-Jun1.63
25-Jun1.63
25-Jun1.11
25-Jun1.52
 
Upvote 0
Thanks Steve, ..
Peter?
Edit: Name correction noted as per your direct message. (y)


looking back on this solution, which works great for me. I was wondering since I apply this formula to a very large data set - approx 80,000 rows..... Is there a faster solution,
I was answering the question that you asked - a faster method for a solution that "works great" for you. ;)


I want to rank the Value (without duplicates) where the Identifier AND Date are the same. I have manually added the desired result for example.
This is a very different question. Not only have you introduced other columns that were not mentioned in post 1 or shown in your post 1 formula, but you also now seem to be ranking low numbers first rather than high numbers as in your post 1 formula and the suggestion that you said "works great".
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top