+ Reply to Thread
Results 1 to 3 of 3

Excel 2007 : Need to get subtotal based on another column's unique values

  1. #1
    Registered User
    Join Date
    02-09-2011
    Location
    Portland, oregon
    MS-Off Ver
    Excel 2007
    Posts
    16

    Smile Need to get subtotal based on another column's unique values

    I have an excel workbook with 4,398 rows. This workbook has multiple filters. What I want to do is have a total of values based on the unique values in another column...BUT, tricky part...want the MAX counted only. Let me demonstrate:

    Mileage pkey
    0.7 7204
    0.01 11450
    1.36 6735
    5.9 10034
    1.36 6735
    0.15 6636
    0.93 7763

    In this example the total for MILEAGE is what I am looking for based on Unique pkey. This is also a FILTERED subset of the data so it would have to know to only total these 7 not the entire 4398 rows. My total in this example SHOULD be 9.05.

    Now lets throw a second example up - lets say the data looks like this

    Mileage pkey
    0.7 7204
    0.01 11450
    1.36 6735
    5.9 10034
    1.5 6735
    0.15 6636
    0.93 7763

    Notice for pkey 6735 I have two mileages - I just want the MAX mileage added. So my total in this case would be 9.19 (again a filtered subset of almost 5000 records with 5 other columns being filtered, such as date and state, etc). I dont mind a VBA function, or a button to push to get the answer - - I would prefer to just have it update automatically on filter though.

    I am very comfortable with VBA and Macros and functions / formulas / arrays. Getting close with a lot of help from this forum - just not quite gettting the right result set.

    Any help??? Thanks!!!!
    Attached Files Attached Files
    Last edited by pjkeady; 02-14-2011 at 03:53 PM. Reason: Added a sample of my excel sheet for clarification

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Need to get subtotal based on another column's unique values

    Try this UDF, I gave up with native formula (That should bring out the cavalry.....)

    Please Login or Register  to view this content.

    Enter in Excel
    Please Login or Register  to view this content.

    Syntax
    SumMaxVisiblePkey(Pkey Range,Mileage Range)

    If you use whole column references the function will trim to Row1 to Last Used Row

    If you have Numeric data above or below the query range then enter the function
    Like
    Please Login or Register  to view this content.

    When you apply filters the function will recalculate the visible rows.

    Hope this helps
    Attached Files Attached Files
    Last edited by Marcol; 02-10-2011 at 05:53 AM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Registered User
    Join Date
    02-09-2011
    Location
    Portland, oregon
    MS-Off Ver
    Excel 2007
    Posts
    16

    Thumbs up Re: Need to get subtotal based on another column's unique values

    Awesome job Marcol !!! Very well done. Checked against 4 years worth of back data and you matched it perfectly. A++++

    Marking as answered!!!
    ----

+ 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