In the previous article we learned how to sum up top or bottom N values. In this article we try to sum up top or bottom N values with a criteria.
Sum of TOP N values with criteria
How to solve the problem?
For this article we will be required to use the SUMPRODUCT function. Now we will make a formula out of these functions. Here we are given a range and a criteria. We need to get the top 5 values in the range and get the sum of the values based on the given criteria.
Generic formula:
list: criteria list
Criteria: criteria to match
range: range of values
values: numbers separated using the commas like if you wish to find the top 3 values, use { 1 , 2 , 3 }.
Example:
Here we have the dataset values from A1:D50.
Firstly, we need to find the top five values using the LARGE function which matches the city "Boston" and then sum operation be performed over those 5 values. Now we will use the following formula to get the sum
Use the Formula:
Explanation:
= SUMPRODUCT { 193 , 149 , 138 , 134 , 123 }
Here the City & quantity range is given as the named range. Press Enter to get the SUM of the top 5 numbers.
As you can see in the above snapshot, that sum is 737. The sum of the values 193 + 149 + 138 + 134 + 123 = 737.
You can check the above values in dataset using the excel filter option. Apply the filter to the City & quantity header and click the arrow button on the city header which appears. Follow the steps as shown below.
Steps:
As you can see in the above gif all the 5 values which match the given criteria. This also means the formula works fine to get the count of these values
LARGE N numbers
The above process is used to calculate the sum of a few numbers from the top. But to calculate for n (large) number of values in a long range.
Use the formula:
Here we generate sum of top 10 values via getting an array of 1 to 10 { 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ; 10 } using the ROW & INDIRECT Excel functions.
Here we have the sum of the top 10 numbers which results in 1147.
Sum of Bottom N values with criteria
How to solve the problem?
For this article we will be required to use the SUMPRODUCT function. Now we will make a formula out of these functions. Here we are given a range and we need to bottom 5 values in range and get the sum of the values.
Generic formula:
Range: range of values
Values : numbers separated using the commas like if you wish to find the bottom 3 values, use { 1 , 2 , 3 }.
Example:
All of these might be confusing to understand. So, let's test this formula via running it on the example shown below.
Here we have a range of values from A1:D50.
Here the City & quantity range is given as using the named range excel tool.
Firstly, we need to find the bottom five values using the SMALL function which matches criteria and then sum operation be performed over those 5 values. Now we will use the following formula to get the sum
Use the Formula:
DON'T use curly braces manually. Curly braces applied using the Ctrl + Shift + Enter in place of just Enter.
Explanation:
= SUM ( { 23 , 27 , 28 , 28 , 30 } ) )
Here the City & quantity range is given as the named range. Press Ctrl + Shift + Enter to get the SUM of the bottom 5 numbers as this is an array formula.
As you can see in the above snapshot that sum is 136.
The above process is used to calculate the sum of a few numbers from the bottom. But to calculate for n (large) number of values in a long range.
Use the formula:
DONOT use the curly brackets manually. Use the Ctrl + Shift + Enter in place of using the Enter.
Here we generate sum of bottom 10 values via getting an array of 1 to 10 { 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ; 10 } using the ROW & INDIRECT Excel functions.
Here we have the sum of the bottom 10 numbers which will result in 155.
Here are some observational notes shown below.
Notes:
Hope this article about how to Return Sum of top 5 values or bottom 5 values with criteria in Excel is explanatory. Find more articles on SUMPRODUCT functions here. Please share your query below in the comment box. We will assist you.
If you liked our blogs, share it with your friends on Facebook. And also you can follow us on Twitter and Facebook. We would love to hear from you, do let us know how we can improve, complement or innovate our work and make it better for you. Write us at info@exceltip.com
Related Articles
How to use the SUMPRODUCT function in Excel: Returns the SUM after multiplication of values in multiple arrays in excel.
SUM if date is between : Returns the SUM of values between given dates or period in excel.
Sum if date is greater than given date: Returns the SUM of values after the given date or period in excel.
2 Ways to Sum by Month in Excel: Returns the SUM of values within a given specific month in excel.
How to Sum Multiple Columns with Condition: Returns the SUM of values across multiple columns having condition in excel
How to use wildcards in excel : Count cells matching phrases using the wildcards in excel
Popular Articles
50 Excel Shortcut to Increase Your Productivity
If with conditional formatting
Convert Inches To Feet and Inches in Excel 2016
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.