You are nesting two aggregations functions: max(sum. That's only possible if you use the aggr function so you can specify what dimension(s) the outer aggregation function needs to aggregate over. So you need something like max(aggr(sum(....), Dim1, Dim2, ... DimN)).
Replace Dim1, Dim2, ... DimN with the dimensions over which the sums should be grouped to calculate the max of the sums.