+ Reply to Thread
Results 1 to 6 of 6

Two formulae to calculate the sum of top 3 cells for a category?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019, Microsoft 365.
    Posts
    440

    Two formulae to calculate the sum of top 3 cells for a category?

    Dear all,

    I used two different formulae to calculate the sum of top 3 cells for a category. Text values or errors are both taken into account. The two formulae used are:

    =SUM(LARGE(IF(A2:A11="Medium",IF(ISNUMBER(B2:B11),B2:B11,""),""),ROW(INDIRECT(("1:3")))),0)

    =SUM(IF((A2:A11="Medium")*(RANK(B2:B11,B2:B11)<=3),B2:B11,0))

    The first one works well, but the second one does not. I tried to repair the second one, but failed

    I attached the sample here. Can you please have a look to modify formula 2?

    Thanks a lot in advance.

  2. #2
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Two formulae to calculate the sum of top 3 cells for a category?

    Your first formula can be shortened to
    =SUM(LARGE(IF(A2:A11="Medium",IF(ISNUMBER(B2:B11),B2:B11,""),""),{1,2,3}))

    An reason, why you want to use the RANK function?
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  3. #3
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019, Microsoft 365.
    Posts
    440

    Re: Two formulae to calculate the sum of top 3 cells for a category?

    Quote Originally Posted by Ace_XL View Post
    Your first formula can be shortened to
    =SUM(LARGE(IF(A2:A11="Medium",IF(ISNUMBER(B2:B11),B2:B11,""),""),{1,2,3}))

    An reason, why you want to use the RANK function?
    Hi Ace_XL, thanks for the idea to shorten the formula.

    In terms of the RANK() function, it is just a curiosity to get it work. But if it is not better than the first one, then I just forget about it.

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Two formulae to calculate the sum of top 3 cells for a category?

    why not just stick with the one that works?
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Two formulae to calculate the sum of top 3 cells for a category?

    Hi,

    Forgive me for asking, but why do you need two formulas?

    There are several things wrong with your second formula:

    1) You are asking it to return the sum of values when the Quality is "Medium" and the Rank is <=3. However, this Rank you are taking over the entire range, NOT the subset of those which have a Quality of "Medium". So, for example, the 2nd ranked value from amongst those with a Quality of "Medium" (492.98) is actually ranked 4th out of the larger set and so will be excluded from your summation.

    2) You have not excluded potential errors or text values (N/A, #DIV/0! - this is the function of the IF(ISNUMBER) part of the other formula), and the RANK function will not accept/ignore these.

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  6. #6
    Forum Contributor
    Join Date
    01-15-2013
    Location
    London
    MS-Off Ver
    Excel 2003, 2007, 2010, 2019, Microsoft 365.
    Posts
    440

    Re: Two formulae to calculate the sum of top 3 cells for a category?

    Thanks for the many great suggestions. I will now stick to the first formula

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1