Looks like this is what you want, the key takeaway being the inner query is wrapped in an outer call to Select()
:
var maxInvestment = TotalUserActions.GroupBy(p => p.Player)
.Select(g => g.GroupBy(x => x.RoundId)
.Select(x => x.LastOrDefault())
.Sum(x => x.BetSize))
.Max();
I do question your use of LastOrDefault()
though as, since you have not specified any ordering, you may as well use FirstOrDefault()
and save the hassle of skipping to the last element.