+ Reply to Thread
Results 1 to 5 of 5

sum top x values according to reference cell

  1. #1
    Registered User
    Join Date
    02-15-2012
    Location
    uk
    MS-Off Ver
    Excel 2010
    Posts
    14

    sum top x values according to reference cell

    Hi please help. By reading these board I have found how to sum the top (X) values in a range, for instance using the following:
    (SUM(LARGE(C5:G5,{1,2,3}))
    This sums the top 3 values in the range c5:g5.
    If I want to change the numbers of values to say the top 4 values or 2 values i can edit the formula accordingly. However, can I create a reference cell (say, B1) where i enter the number of values i want to total, and the formula would auto calculate?

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: sum top x values according to reference cell

    Here, try this:

    =SUMPRODUCT(LARGE(C5:G5,ROW(A1:INDEX(A:A,B1,))))

  3. #3
    Registered User
    Join Date
    02-15-2012
    Location
    uk
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: sum top x values according to reference cell

    wow!!! thanks for very speed reply, which works! Couple of questions tho
    I need to copy this down around 10 rows, so have fixed the A1:index A:A, B1).It seems to work ok, but I dont know what the Row A1:indexA:A means!!! obviously b1 is the ref cell (which in my sheet is actually h4
    Many many thanks, very impressive!!

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: sum top x values according to reference cell

    If you moving it around then use $:

    =SUMPRODUCT(LARGE(C5:G5,ROW($A$1:INDEX($A:$A,$B$1,))))

    Instead of B1 you can chose to whatever you want (only use $ around: $H$1).
    Also range you can change (C5:G5).

    But the rest don't change.

    ROW(A1:A7) will give you array of first 7 numbers (1,2,3,4,5,6,7)
    ROW(A1:A100) will give you array of first 100 numbers.

    Since you don't know how many you'll use (it's defined by B1) then you need INDEX formula to determine second value.

    Therefore if B1=100 INDEX(A:A, B1) will return A100
    so ROW($A$1:INDEX($A:$A,$B$1,)))) will return you 1,2,3,4,5....,97,98,99,100
    And that's exactly you used in your first formula {1,2,3} only for variable lenght.

    (note: you can also try to use SUM(LARGE(C5:G5,ROW(A1:A3))) in your formula)

    So.. When you moving this formula around you always need to be referencing to row number of A1 to An no matter what range you use in calculation.
    To be more precise you can use any column but row from 1 to n (i.e. SUM(LARGE(C5:G5,ROW(M1:M3)))
    Last edited by zbor; 02-15-2012 at 06:04 AM.

  5. #5
    Registered User
    Join Date
    02-15-2012
    Location
    uk
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: sum top x values according to reference cell

    thats great, many thanks indeed, very impressed! kind regards from sunny west yorkshire

+ 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