+ Reply to Thread
Results 1 to 8 of 8

Summing the top 80% of the values in a column?

  1. #1
    Registered User
    Join Date
    04-28-2010
    Location
    Maricopa, AZ
    MS-Off Ver
    Excel 2003
    Posts
    7

    Summing the top 80% of the values in a column?

    I have a Excel 2007 table linked to an external data source that has a column that shows a value anywhere from 0 up to around 600. This column is sorted in ascending order and ther will always be filters on other columns in the table. Also, the # of records in this table can change. This is on a sheet called Raw Data.

    On another sheet, I ideally need to show the sum of the top 80% of the values in this column, while only looking at the records that have been filtered. It would be great to have this done in 1 formula.

    If doing this with 1 formula is not an option, I thought I could count the # of records showing after my filters in 1 cell (for example 285). Then I can calculate 80% of this count in another cell (example 228). Then I can use a variant of the formula below (where D3 is the cell with the calculated 80% count).

    =SUMPRODUCT(LARGE(A:A,ROW(INDIRECT("1:" & D3))))

    I actually have this working with the calculations on the same sheet as the column and when there is no filter.

    Any help would be greatly appreciated.

    Thanks!

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Summing the top 80% of the values in a column?

    IMO in these scenarios it's often useful to make use of an additional column adjacent to source that utilises the SUBTOTAL function on a row by row basis... this column can greatly simplify subsequent formulae.

    Based on your requirements of:

    Quote Originally Posted by cherman
    I thought I could count the # of records showing after my filters in 1 cell (for example 285). Then I can calculate 80% of this count in another cell (example 228). Then I can use a variant of the formula below (where D3 is the cell with the calculated 80% count).
    I would suggest perhaps

    'Raw Data'!D2:
    =IF(SUBTOTAL(2,C4),C4,"")
    copied down for all rows
    [edit: assumed for sake of demo. that source fields in Table are A:C with numerics in C]

    Your summary formula thus becomes:

    =SUM('raw data'!$D$2:INDEX('raw data'!$D:$D,MATCH(SMALL('raw data'!$D:$D,ROUNDDOWN(COUNT('raw data'!$D:$D)*0.8,0)),'raw data'!$D:$D,0)))

    Notes:
    --it is assumed row 1 on Raw Data contains headers
    -- we use MATCH of nth value rather than a SUMIF so as to account for possibility of duplicity of nth value where duplicate(s) are to be excluded given restriction is based on 80% count
    -- ranges used (ie Col D) is for demo. purposes only - adjust as nec.
    Last edited by DonkeyOte; 07-16-2010 at 03:14 AM.

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Summing the top 80% of the values in a column?

    edit: the above is incorrect actually as it's summing the bottom 80% - oops, modified for the top 80% (again trying to account for possibility of duplicity):

    =SUM('raw data'!D:D)-SUM('raw data'!D1:INDEX('raw data'!D:D,MATCH(SMALL('raw data'!D:D,ROUNDUP(COUNT('raw data'!D:D)*0.2,0)),'raw data'!D:D,0)))

  4. #4
    Registered User
    Join Date
    04-28-2010
    Location
    Maricopa, AZ
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Summing the top 80% of the values in a column?

    Thanks very much for your help!

    I tried out the formula you gave me and I found a couple of problems.

    1) There are 8529 rows of data. Your formula seems to be taking the top 6966 rows into consideration and giving a count of 180835. When I manually calculated what the top 80% of the rows were (by counting the total # of rows and multiplying by 80%), I got 6832. The top 6832 rows give a sum of 180299. There is an obvious discrepancy here.

    2) The formula doesn't take filtering into consideration, which is a necessity. There will always be filtered rows.

    Do you have any suggestions on how to fix these issues?

    Thanks!

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Summing the top 80% of the values in a column?

    Perhaps it would be simplest to approach from another angle.

    Again - assuming same set up as before in so far as values to sum are listed in C (when visible) and that values are listed in Ascending order then:

    'Raw Data'!D1
    =SUBTOTAL(2,$C$2:$C$10001)

    'Raw Data'!D2
    =IF(SUBTOTAL(2,$C$2:$C2)<=$D$1,"",SUBTOTAL(9,$C2))
    copied down to say C10001

    The result is simply the sum of D (less D1 of course)
    Last edited by DonkeyOte; 07-22-2010 at 05:07 PM.

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Summing the top 80% of the values in a column?

    If you want a single formula then try this, assuming data in A2:A10000

    =SUBTOTAL(9,INDEX(A2:A10000,LARGE(IF(SUBTOTAL(2,OFFSET(A2,ROW(A2:A10000)-ROW(A2),0)),ROW(A2:A10000)-ROW(A2)+1),ROUND(SUBTOTAL(2,A2:A10000)*0.8,0))):A10000)

    confirmed with CTRL+SHIFT+ENTER
    Audere est facere

  7. #7
    Registered User
    Join Date
    08-01-2016
    Location
    Chennai
    MS-Off Ver
    2010
    Posts
    7

    Re: Summing the top 80% of the values in a column?

    Hi, i am new user to excel
    Need help on summing top values to match 80% of grand total and Count of rows matching 80% value
    Would like to learn creating formula / vba based macro to for quicker solution.

    Manual Steps followed by me.
    1. Sort in descending order
    2. Sum total value and obtain grand total
    3. Identify 80% of grand total & manually count no. of rows to match 80% value.

    Any one to help.. would love to learn more.
    (Sample values given below)


    101130
    316447
    103027
    970754
    1481220
    202576
    157433
    385807
    105081
    848441
    121587
    246354
    229157
    211966
    114263

    Result observed manually is

    Grand total : 5595245
    ~80% of value to grand total : 4478180
    Count of rows for ~80% value : 7

    Can anyone help me to drive formula to obtain this !!!!

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,990

    Re: Summing the top 80% of the values in a column?

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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