How to calculate a sum or an average of top 3 maximal values?
Sum of top 3 values
In Legacy Excel, we can use the LARGE function, in which we need to select the range for our calculation. In the k argument let’s write 1 (Fig. 1).
=LARGE($C$2:$C$33,1)
Fig. 1 LARGE function
After entering the function, we have the largest value (Fig. 2).
Fig. 2 The largest value
Now, we can copy the function and add the second and the third largest value (Fig. 3).
This way we have the sum of 3 largest values (Fig. 4).
Fig. 4 The sum of 3 largest values
This solution, however, is the least dynamic of all solutions we have. We can make this formula shorter by hardcoding our values. We have to write 1, 2 and 3 as an array (Fig. 5).
=LARGE($C$2:$C$33,{1;2;3})
Fig. 5 The first, second and third value written as an array
This way Excel will return three largest values. I’m using Dynamic Excel, so the results are spilled (Fig. 6).
Fig. 6 Spilled results
Now, that our values have been hard-coded, we can sum them by using the SUM function. We can also use this function to sum up averages (Fig. 7).
=SUM(LARGE($C$2:$C$33,{1;2;3}))
Fig. 7 Summing up the largest values
Our results (Fig. 8).
Fig. 8 Results
This solution, however, is hard to modify, so we can make it a bit more dynamic. We can use the ROW function and select the first three rows from the sheet. This way our solution is more dynamic (Fig. 9).
=SUM(LARGE,($C$2:$C$33,ROW(A1:A3)))
Fig. 9 A more dynamic solution
Results (Fig. 10).
Fig. 10 Results
But, in Legacy Excel, we should use the SUMPRODUCT function instead of the SUM function or use the Ctrl + Shift + Enter shortcut to put the formula into the cell (Fig. 11).
=SUMPRODUCT(LARGE,($C$2:$C$33,ROW(A1:A3)))
Fig. 11 SUMPRODUCT function
And we have the result. In the second column, in Dynamic Array Excel, we still need the SUM and LARGE functions, then the array which is the range we will look at. Then, we can use the SEQUENCE function to create a sequence of proper numbers, let’s take 3 (Fig. 12).
=SUM(LARGE($C$2:$C$33,SEQUENCE(3)))
Fig. 12 Adding the SEQUENCE function
We have proper results (Fig. 13).
Fig. 13 Results
This solution is much more dynamic. Let’s change the number into 5 (Fig. 14).
=SUM(LARGE($C$2:$C$33,SEQUENCE(5)))
Fig. 14 3 changed into 5
Here is the result (Fig. 15).
Fig. 15 Results
In Legacy Excel, we can also change one number. Let’s change the number of rows in the range from 3 to 5 (Fig. 16).
=SUMPRODUCT(LARGE($C$2:$C$33,ROW(A1:A5)))
Fig. 16 A3 into A5
And we have the same result (Fig. 17).
Fig. 17 Result
We have to remember which version of Excel we have and which solution we can use.
We can count the number of spaces between words. Let’s have a look at our first example. In cell A2, we have spaces between words and at the end of each line, so the case is simple. We can use the LEN function here that counts the length of text (Fig. 1).
=LEN(A2)
Fig. 1 LEN function
Now, that we have the number of signs, we can remove spaces. We can use the SUBSTITUTE function here. This function will change the old text, which in our case is a space into new text. And since we want to remove spaces, our new text will be an empty text string written in double quotes (Fig. 2).
=SUBSTITUTE(A2,” “,“”)
Fig. 2 SUBSTITUTE function
We can see that the function removed all spaces from our text (Fig. 3).
Fig. 3 No spaces
Now, we can count the length of the text without spaces using the LEN function (Fig.4).
=LEN(SUBSTITUTE(A2,” “,“”)
Fig. 4 Counting the text length
Now we know the length (Fig. 5).
Fig. 5 Text length
Since we know how many spaces there are, we can use the formula to count the words. We just have to subtract this formula from the previous one (Fig. 6).
=LEN(A2)-LEN(SUBSTITUTE(A2,” “,“”))
Fig. 6 Subtracting formulas
And we have the number of spaces (Fig. 7).
Fig. 7 Number of spaces
We still have to remember that to count the number of words, we have to add 1 because there is only one space between two words (Fig. 8).
=LEN(A2)-LEN(SUBSTITUTE(A2,” “,“”))+1
Fig. 8 One space between two words
Now we know the number of words in each cell.
Fig. 9 Number of words
If we want to count words from all cells, we can use almost the same formula. The only thing we have to change is the range which now will be from A2 to A4 (Fig. 10).
=LEN(A2:A4)-LEN(SUBSTITUTE(A2:A4,” “,“”))+1
Fig. 10 Adding a new range
In Dynamic Array Excel, the results will be spilled, however we can sum the up (Fig. 11).
Fig. 11 Split results
In the previous version of Excel we can use the the SUMPRODUCT function (Fig. 12).