Monday, February 1, 2010

Excel Formula : Sum top 5 in unsorted range

Today I am sharing a formula to sum top 5 values in an unsorted range.

=SUMPRODUCT(LARGE(Data,ROW(1:5)))

See the screen cast below to know secret behind this formula.

Photobucket

Actually we are using array formula to find top 5 values , then summing them to find the sum of top 5 values in unsorted range.

From the screen cast you can see that

1. We are entering this formula using sumproduct, which is shortcut to enter array formulas in excel.
2. Data is a named range A3 to B36
3. We are using excel function Large to find Top values.
4. Row(1:5) - is is shortcut to create an array of numbers {1,2,3,4,5} as Kth position

This leads to find top 5 values in unsorted range and then summing them.

Food for thought :

Just change Row(1:5) to Row(1:10) you will be able to find Top 10 values.

Or Change Large with small to find out bottom 5 values.

Download Excel file with formula to sum top 5 values in an unsorted range

to play furhter with this formula

5 comments:

kemas said...

we can use
=SUM(LARGE(Data;ROW(1:5)))
and click
Ctrl + Enter

kemas said...

sorry!
Ctrl +Shift+ Enter

Yogesh Gupta said...

Hello kemas

Thanks for your inpputs. I use sumproduct as workaround to enter CSE(Array) Formulas. The problem with the CSE formulas is exactly the same as you made mistake while writing this comment. In case user does not enter it with Ctrl+Shift+Enter it does not work.

Problem gets compounded when some one using your worksheet tries to modify your CSE formula. If that user is not aware of CSE formulas, he will never figure out why the formula stoped working.

Just write Sumproduct(Your CSE formula) all these issues disappear

Thanks

SmprFidels said...

What if all the cells in your data range don't have data yet? is there a way to only total the ones that are there up to a certain number? I tried using something like =SUMPRODUCT(LARGE(E9:N9,ROW(INDIRECT("1:B2"))))
where B2 is a cell containing =COUNTIF(E9:N9,">0") to count how many data points exist at this point.

Yogesh Gupta said...

@ SmprFidels

Formula will not work the way you have constructed it. How ever if your data has less then 5 numbers you can use sum instead of sumproduct as above. This can be handled using if function.

I would have deployed following formula in situation like yours

=IF(COUNT(E9:N9)<5,SUM(E9:N9),(SUMPRODUCT(LARGE(E9:N9,ROW(1:5)))))

I hope this helps, let me know in case you need further help
Regards

Post a Comment