# Sum top n values

An excel formula to sum top n values

### Related Functions

`=SUMPRODUCT(LARGE(rng,{1,2,N}))`

To sum the top values in a range, you can use a formula based on the LARGE function, wrapped inside the SUMPRODUCT function. In the generic form of the formula (above), rng represents a range of cells that contain numeric values and N represents the idea of Nth value.

In the example, the active cell contains this formula:

`=SUMPRODUCT(LARGE(C5:C14,{1,2,3,4}))`

### Here's how the formula works

In its simplest form, LARGE will return the "Nth largest" value in a range. For example, the formula:

`=LARGE (C5:C14, 4)`

will return the 4th largest value in the range C5:C14 which, in the example above, is the number 13.

However, if you supply an "array constant" (e.g. a constant in the form {1,2,3,4}) to LARGE as the second argument , LARGE will return an array of results instead of a single result. So, the formula:

`=LARGE (C5:C14,{1,2,3,4})`

Will return the 1st, 2nd, 3rd and 4th largest value in the range C5:C14. In the example above, where C5:C14 contains the numbers 1-19, the result from LARGE will be the array {13,15,17,19}. SUMPRODUCT then sums the numbers in this array and returns a total, which is 64.

Using SUMPRODUCT avoids the complexity of entering an array formula, but it is still processing arrays. You can also write an array formula directly using SUM:

`{=SUM(LARGE(C5:C14,{1,2,3,4}))}`

Note that you must enter this formula as an array formula.

When N becomes large it becomes tedious to create the array constant by hand - If you want to sum to the top 20 or 30 values in a large list, typing out an array constant with 20 or 30 items will take a long time. In this case, you can use a shortcut for building the array constant that uses the ROW and INDIRECT functions.

For example, if you want to SUM the top 20 values in a range called "rng" you can write a formula like this:

`=SUMPRODUCT(LARGE(rng,ROW(INDIRECT("1:20"))))`