League Table

jimrward

Well-known Member
Joined
Feb 24, 2003
Messages
1,896
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
  8. 2003 or older
Platform
  1. Windows
Having a play with Power Tools to try and produce a league table of top scores
Simple data example
Golfer, Date, score
Looking for a league table max score to lowest score where golfer only appears once in the list
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Would you supply some sample data for us to work with. Post it using XL2BB. No pictures as they cannot be manipulated.
 
Upvote 0
apologies for the delay here been taking timeout
here is some sample data and the expected result in columns E and F, might be worth including an insight on an additional parameter say Junior/Senior and the possibility of grouping by year and quarter so i can understand the mechanics

Book1
ABCDEF
1DatePlayerStablefordPlayerScore
205/06/2023jim24dave29
305/06/2023fred27jim28
405/06/2023bob21fred27
507/07/2023dave29billy24
607/07/2023jim25bob21
707/07/2023billy24
807/07/2023jim28
Sheet1
 
Upvote 0
How about this?

PQ
ABCDEF
1DatePlayerStablefordPlayerTop Score
26/5/2023jim24dave29
36/5/2023fred27jim28
46/5/2023bob21fred27
57/7/2023dave29billy24
67/7/2023jim25bob21
77/7/2023billy24
87/7/2023jim28
Sheet1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"Player"}, {{"Top Score", each List.Max([Stableford]), type number}}),
    Sort = Table.Sort(Group,{{"Top Score", Order.Descending}})
in
    Sort
 
Upvote 0
many thanks for the above help, I would like to include an additional column, the date the score was achieved as follows
power query example.xlsx
ABCDEFG
1DatePlayerStablefordPlayerScoreDate Achieved
205/06/2022jim24dave2907/07/2022
305/06/2022fred27jim2808/07/2022
403/06/2022bob21fred2705/06/2022
507/07/2022dave29billy2407/07/2022
607/07/2022jim25bob2103/06/2022
707/07/2022billy24
808/07/2022jim28
Sheet1
 
Upvote 0
I asked this question earlier in the year and now revisiting for reference and noted that there wasn’t a solution to the last entry above which I had piggybackEd on more in hope than anything else

how to include the date of the high score, when I group by player and grab the max the date column gets lost

i haven’t started a new thread so as not to replicate the pertinent information above
 
Upvote 0
One way I can think, looking up for the Top Score value in the filtered PlayerRows table (added in the Group step), sorting the matching rows by date (desc), so we get the latest max score of the player if there are more than one, then selecting the top row. Then convert the record list to table, etc..

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"Player"}, {{"Top Score", each List.Max([Stableford]), type any}, {"PlayerRows", each _, type nullable table[Date = any, Player = any, Stableford = any]}}),
    Lookup = Table.TransformRows(Group, 
                        (r) => Table.First(
                                    Table.Sort(
                                        Table.SelectRows(r[PlayerRows], 
                                            (c) => c[Stableford] = r[Top Score]),
                                        {{"Date", Order.Descending}}
                                    )
                                )),
    ToTable = Table.FromList(Lookup, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    Result = Table.Sort(Table.ExpandRecordColumn(ToTable, "Column1", {"Player", "Stableford", "Date"}, {"Player", "Top Score", "Date"}), {{"Top Score", Order.Descending}})
in
    Result

pq.jpg
 
Upvote 0
A similar approach:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    ChangeType = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Stableford", Int64.Type}}),
    Table_Sort = (tbl as table)=> Table.Sort(tbl,{{"Stableford", Order.Descending}, {"Date", Order.Descending}}),
    Group = Table.Group(ChangeType, {"Player"}, {{"Record", each Table_Sort(_){0}}}),
    Result = Table_Sort(Table.FromRecords(Group[Record]))
in
    Result
 
Upvote 0
@smozgur @JGordon11 many thanks for the excellent solutions both
Just so I can understand further the Table.Sort you both refer to is this entered freehand in the Advanced View editor, as when I try to sort anything I get sorted_rows rather than sorted_table in Excel PQ
Once I understand this I will hopefully apply to the huge data set I have, the example above is just a simple data table purely for research purposes
 
Upvote 0

Forum statistics

Threads
1,223,936
Messages
6,175,508
Members
452,650
Latest member
Tinfish

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