Recursive LAMBDA for progressive SMALL calculations

macfuller

Active Member
Joined
Apr 30, 2014
Messages
319
Office Version
  1. 365
Platform
  1. Windows
I have inherited a golf pool spreadsheet (see below) for the Masters. You initially pick 10 golfers for the tournament on the assumption that some (even Jordan Spieth!) will miss the cut. The 6 best golfers of your picks after the cut have the difference in their score from the tournament leader added up for all 4 rounds. If you don't have 6 golfers who made the cut you're out of the pool. deChambeau didn't get much love from our group this year!

You can see in cell I3 that currently Player 1's golfers are 24 above deChambeau, with Koepka and Morikawa having not finished Round 1. Invalid or missing rounds leave the Actual Total column at 0.

The SUMPRODUCT function in I3 works fine.
Excel Formula:
=LET(
     ScoreDifference, SUMPRODUCT(
        NOT(ISBLANK(tblResults[Player 1])) * (tblResults[[Actual Total]:[Actual Total]]<>0),
        tblResults[[Actual Total]:[Actual Total]] - Leader_Score),
    Result, IF(ScoreDifference = 0, 999, ScoreDifference),
    Result
    )
But in order to handle the cut from 10 to 6 players it is necessary to eliminate the "x" against the dud players, although one can just stop reporting the scores on the others. But since I just copy the round numbers from the ESPN scorecard into the spreadsheet I either blank out every non-pool golfer or delete the "x".
I'd like a simpler way to recursively calculate the SMALL function using the # Selections value in F3. I'm new to LAMBDA functions but I'm hoping there's a way to actually do something in the pseudo-code below...
Excel Formula:
=LET(
    ScoreArray, -get the Actual Total array for the Player-
    SmallTotal, Recursive LAMBDA(RunningTotal, SMALL(ScoreArray,6...1),
    RunningTotal
)

Any chance of this? Thanks.

2024 MCC Masters.xlsx
ABCDEFGHI
2# SelectionsPlayer 1
36Cumulative Strokes Above Leader24
4Rank5
5Golfers not being tracked should have nothing or zero entered for each round
6Cut or withdrawn golfers should get "CUT" or "WD" in the Status column
7 or have all round scores removedLeader Score
8Scoreboard65
9GolferDay 1Day 2StatusDay 3Day 4Actual TotalNum PicksPlayer 1
10Åberg, Ludvig01
12Bhatia, Akshay01
13Bradley, Keegan01
15Cantlay, Patrick71711
16Clark, Wyndham73731
21Day, Jason02
25Eckroat, Austin74741
28Fitzpatrick, Matt71711
35Hadwin, Adam75751
37Harman, Brian01
38Hatton, Tyrrell01
44Hovland, Viktor71714x
54Koepka, Brooks08x
60Matsuyama, Hideki76767x
61McCarthy, Denny74741
62McIlroy, Rory71715x
66Morikawa, Collin01x
68Niemann, Joaquín70703
71Pavon, Matthieu01
73Rahm, Jon73739
76Schauffele, Xander72727
77Scheffler, Scottie666611x
84Spieth, Jordan03
Pool Selections
Cell Formulas
RangeFormula
I2I2=INDEX(tblResults[#Headers],COLUMN())
I3I3=LET( ScoreDifference, SUMPRODUCT( --(NOT(ISBLANK(INDIRECT("tblResults[" & I2 & "]")))) * (tblResults[Actual Total]<>0), tblResults[Actual Total] - Leader_Score), Result, IF(ScoreDifference = 0, 999, ScoreDifference), Result )
I4I4=RANK(I3,$I$3:$AF$3,1) +COUNTIF($I3:I3,I3)-1
G8G8=IFERROR( SMALL( tblResults[Actual Total], COUNTIF( tblResults[Actual Total], "<=" & 0 ) + 1 ), "n/a" )
G10,G12:G13,G15:G16,G21,G25,G28,G35,G37:G38,G44,G54,G60:G62,G66,G68,G71,G73,G76:G77,G84G10=LET( GolferScore, [@[Day 1]] + [@[Day 2]] + [@[Day 3]] + [@[Day 4]], Round1Played, COUNTA([Day 1]) > 0, Round2Played, COUNTA([Day 2]) > 0, Round3Played, COUNTA([Day 3]) > 0, Round4Played, COUNTA([Day 4]) > 0, GolferCut, NOT(ISBLANK([@Status])), c_01, "If a round has been played but there's no score for the golfer, set total score to 0", IgnoreRound1, AND([@[Day 1]]=0,Round1Played), IgnoreRound2, AND([@[Day 2]]=0,Round2Played), IgnoreRound3, AND([@[Day 3]]=0,Round3Played), IgnoreRound4, AND([@[Day 4]]=0,Round4Played), KeepScore, (NOT(GolferCut) * NOT(IgnoreRound1) * NOT(IgnoreRound2) * NOT(IgnoreRound3) * NOT(IgnoreRound4)) = 1, IF(KeepScore, GolferScore, 0) )
H10,H12:H13,H15:H16,H21,H25,H28,H35,H37:H38,H44,H54,H60:H62,H66,H68,H71,H73,H76:H77,H84H10=COUNTA(tblResults[@[Player 1]:[P20]])
Named Ranges
NameRefers ToCells
Leader_Score='Pool Selections'!$G$8I3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
I9:AB9Expression=COUNTA(I$10:I$98) <> $F$3textNO
 

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.
BTW, My LAMBDA attempt is getting a #VALUE error, probably because I don't understand how to properly record the variables.

My LAMBDA function is defined as FindSmallLambda in Name Manager as
Excel Formula:
= LAMBDA(SmallValue,Data,IF(SmallValue>0,FindSmallLambda(SmallValue-1,Data,SMALL(Data,SmallValue)),0))

And the cell calling it has
Excel Formula:
=LET(
    ScoreArray,  NOT(ISBLANK(tblResults[Player 1])) * ( tblResults[[Golfer Total]:[Golfer Total]] - Leader_Score) * (tblResults[[Golfer Total]:[Golfer Total]]<>0),
    RunTotal, FindSmallLambda($F$3, ScoreArray),
    RunTotal
)
 
Upvote 0

Forum statistics

Threads
1,215,200
Messages
6,123,601
Members
449,109
Latest member
Sebas8956

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