Combine XLOOKUP and RANK to create ranked dynamic table from static alphabetical table?

chasfh

Board Regular
Joined
Dec 10, 2014
Messages
67
Office Version
  1. 365
Platform
  1. Windows
I have a static table of players in alphabetical order with scores and ranks. I want to create a dynamic second table that reflects the same table in ranked order of points.

My first instinct is that it would combine XLOOKUP and RANK into a single command, but that may not be the way to go, because I am coming up dry when I google around for such a command.

Here is the table in alphabetical order:

PlayerScoreRank
Barrett, S8411
Clark, R868
Duski, M868
Eikenberry, J8411
Helseth, T893
Hopper, B893
Hultquist, B893
James, B893
Kay, G893
Michel, G8510
Muntz, R941
Rankin, T8314
Rosen, R8411
Stephens, C941
Tellman, M8215

The result would look something like this:

PlayerScoreRank
Muntz, R941
Stephens, C941
Helseth, T893
Hopper, B893
Hultquist, B893
James, B893
Kay, G893
Clark, R868
Duski, M868
Michel, G8510
Barrett, S8411
Eikenberry, J8411
Rosen, R8411
Rankin, T8314
Tellman, M8215

The main conditions for this new table must be these:
  • It has to be dynamic so that when scores and ranks change, this second table reflects the new rankings, changing the order of players listed as appropriately ranked.
  • When there is a tie score between or among multiple records, all the tied players must show in the table. For example, there is a five-way tie for third on the example table—in the dynamic table result, all five players must be reflected, as opposed to the same player showing up five times.
Is this possible to do?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try this:
Excel Formula:
=SORT(A2:C16, 2, -1)
or this if you want ties in alphabetical order:
Excel Formula:
=SORT(A2:C16,{2,1},{-1,1})
1734903350079.png
 
Upvote 0
Power Query Solution

Book8
ABCDEFG
1PlayerScoreRankPlayerScoreRank
2Barrett, S8411Muntz, R941
3Clark, R868Stephens, C941
4Duski, M868Helseth, T893
5Eikenberry, J8411Hopper, B893
6Helseth, T893Hultquist, B893
7Hopper, B893James, B893
8Hultquist, B893Kay, G893
9James, B893Clark, R868
10Kay, G893Duski, M868
11Michel, G8510Michel, G8510
12Muntz, R941Barrett, S8411
13Rankin, T8314Eikenberry, J8411
14Rosen, R8411Rosen, R8411
15Stephens, C941Rankin, T8314
16Tellman, M8215Tellman, M8215
Sheet1



Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Sorted Rows" = Table.Sort(Source,{{"Score", Order.Descending}})
in
    #"Sorted Rows"

any changes to the source document will dynamically update the output when you select Data-->Refresh Data
 
Upvote 0
Or if you need to include rank in the formula:
Excel Formula:
=LET(
    a, A2:A16,
    b, B2:B16,
    c, RANK.EQ(--b, b),
    SORT(HSTACK(a, b, c), {2, 1}, {-1, 1})
)
1734904333954.png
 
Upvote 0
I appreciate your efforts but none of these are exactly what I am looking for.

First of all, what I am looking for is a dynamic second table that will automatically sort by highest to lowest point total when I update the original table. Mr. LogChief's formulas don't do that. The second formula with LET might come close but this is the result:

1734988235521.png


There are additional columns because I gave you a simplified example, but the point is, the far left column is what I wanted to sort by, and as you can see, it's out of order.

And Mr. alansidman's Power Query is too advanced for me at the moment, in that I went to this web page hoping I could easily implement it, and I can't, because the instructions are not super exact, which I owuld need, and I would have no idea how to diagnose a less than 100% perfect Power Query.

Is there anything else that could possible work here?
 
Upvote 0
Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

- Follow this link to learn how to install Power Query in Excel 2010 / 2013.

- Follow this link for an introduction to Power Query functionality.

- Follow this link for a video which demonstrates how to use Power Query code provided.
 
Upvote 0
Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

- Follow this link to learn how to install Power Query in Excel 2010 / 2013.

- Follow this link for an introduction to Power Query functionality.

- Follow this link for a video which demonstrates how to use Power Query code provided.

Thanks. I'll look into at some point. Probably not for this because I have many other things on my plate at this second.
 
Upvote 0
Si te funciona con macro prueba de esta manera.

Puede haber una manera de perfeccionar el código, pero es funcional.

https://app.box.com/s/s84egzgiisfaymcm7b1cjaxhy01zd6b2

In a module, I put the following code:
VBA Code:
Sub SincTable()

    Dim Tbl1 As ListObject
    Dim Tbl2 As ListObject
    Dim Rw1 As ListRow
    Dim Rw2 As ListRow
    Dim i As Long, j As Long
    Dim id As Variant
    Dim ColID As Long
    Dim Found As Boolean
    Dim ColSort As Integer
    
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    
    ' Set sheets an tables
    Set Tbl1 = Sheets("Hoja1").ListObjects("Tabla1")  ' Change the sheets name and the table name
    Set Tbl2 = Sheets("Hoja1").ListObjects("Tabla2")  ' Change the sheets name and the table name
    
    ColID = 1                                       ' Change this name to index column of players name
    
    For Each Rw1 In Tbl1.ListRows
        id = Rw1.Range.Cells(1, ColID).Value
        Found = False
        For Each Rw2 In Tbl2.ListRows
            If Rw2.Range.Cells(1, ColID).Value = id Then
                Found = True
                For j = 1 To Tbl1.ListColumns.Count
                    If Rw1.Range.Cells(1, j).Value <> Rw2.Range.Cells(1, j).Value Then
                        Rw2.Range.Cells(1, j).Value = Rw1.Range.Cells(1, j).Value
                    End If
                Next j
                Exit For
            End If
        Next Rw2
        
        ' This line add in table 2 the register if not exist
        If Not Found Then
            Tbl2.ListRows.Add
            For j = 1 To Tbl1.ListColumns.Count
                Tbl2.ListRows(Tbl2.ListRows.Count).Range.Cells(1, j).Value = Rw2.Range.Cells(1, j).Value
            Next j
        End If
    Next Rw1
       
    ' Sort
    ' Name of the table header to sort by (Rank)
    ColSort = Tbl2.ListColumns("Rank").Index ' Change "Rank" if your table header is other

    ' Sort ascending
    Tbl2.Sort.SortFields.Clear
    Tbl2.Sort.SortFields.Add Key:=Tbl2.ListColumns(ColSort).Range, _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers

    Tbl2.Sort.Header = xlYes
    Tbl2.Sort.Apply
    
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    
End Sub

And on sheet 1 to automate the process, place:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Sheets("Hoja1").ListObjects("Tabla1").Range) Is Nothing Then
        Call SincTable
    End If
End Sub

You should also update the formula in column C, the other table don't need it.
My Excel version is in spanish and maybe you get an error.
 
Upvote 0

Forum statistics

Threads
1,225,730
Messages
6,186,698
Members
453,369
Latest member
positivemind

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