+ Reply to Thread
Results 1 to 14 of 14

Subtotal max/min with IF (urgent help required)

  1. #1
    Registered User
    Join Date
    09-01-2011
    Location
    SK
    MS-Off Ver
    Excel 2010
    Posts
    22

    Subtotal max/min with IF (urgent help required)

    I have a table which I need to be able to use the autofilter function on but I want to be able to automatically determine the max and min values in the filtered result set which meet certain criteria.

    AutoFilter Field Criteria Field Value Field
    Orange X 2
    Apple X 10
    Banana Y 12
    Orange X 24
    Apple Z 13
    Banana Z 14
    Banana X 16
    Apple Z 18
    Orange Y 20

    So I need a function that will give me max/min (value field) for the criteria, say X for this example.

    I have tried several variations of the SUMPRODUCT function. This is the latest iteration (105 for min, 104 for max):

    =SUMPRODUCT(MAX(SUBTOTAL(105,OFFSET(Value_Field,ROW(Value_Field)-ROW(Value_Field),)),--(Criteria Field=B2)))

    The problem is that it gives me a the MIN/MAX for the whole filtered set. The criteria is being ignored.

  2. #2
    Valued Forum Contributor Harribone's Avatar
    Join Date
    02-24-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2019/365
    Posts
    570

    Re: Subtotal max/min with IF (urgent help required)

    Only thing i can suggest is creating a new sheet and then copy the filtered data onto this. you can then use the min/max forumlas on this sheet.

    I'm sure someone will give you a more definitive answer but this may help you in the short term.
    Say thanks, click *

  3. #3
    Registered User
    Join Date
    09-01-2011
    Location
    SK
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Subtotal max/min with IF (urgent help required)

    That's not really an option. I generate a report from this data on a regular basis so I need to be able to get this info quickly and easily. Thanks for the suggestion.

  4. #4
    Registered User
    Join Date
    09-01-2011
    Location
    SK
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Subtotal max/min with IF (urgent help required)

    Here is an example file demonstrating what I have done and what/why I need it.

    Apple-orange-banana filter example.xlsx

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Subtotal max/min with IF (urgent help required)

    This is probably what you need.


    Please Login or Register  to view this content.
    sample spreadsheet attached
    Attached Files Attached Files

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

    Re: Subtotal max/min with IF (urgent help required)

    Quote Originally Posted by triver525 View Post
    =SUMPRODUCT(MAX(SUBTOTAL(105,OFFSET(Value_Field,ROW(Value_Field)-ROW(Value_Field),)),--(Criteria Field=B2)))
    You are missing a MIN function around the second ROW function....but still that won't work as is - you have to take just the value of each visible cell which matches the criteria and then take the MAX, e.g. this "array formula"

    =MAX(IF(Criteria_Field=B2,SUBTOTAL(109,OFFSET(Value_Field,ROW(Value_Field)-MIN(ROW(Value_Field)),0,1))))

    confirmed with CTRL+SHIFT+ENTER

    Replace the first MAX only with MIN for the minimum value
    Last edited by daddylonglegs; 02-26-2013 at 06:52 PM.
    Audere est facere

  7. #7
    Registered User
    Join Date
    09-01-2011
    Location
    SK
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Subtotal max/min with IF (urgent help required)

    That is perfect! Thank you very very much.

    As a matter of refinement, can you think of anyway to make the function ignore zeroes? Maybe a nested IF?

  8. #8
    Registered User
    Join Date
    09-01-2011
    Location
    SK
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Subtotal max/min with IF (urgent help required)

    And now I know I'm pushing my luck, can you think of a way to have a second criterion?

  9. #9
    Valued Forum Contributor
    Join Date
    02-05-2013
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2013
    Posts
    571

    Re: Subtotal max/min with IF (urgent help required)

    Why not use pivot table, you can get all without trouble.
    Attached Files Attached Files
    Click (*) if you received helpful response.

    Regards,
    David

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

    Re: Subtotal max/min with IF (urgent help required)

    Quote Originally Posted by triver525 View Post
    As a matter of refinement, can you think of anyway to make the function ignore zeroes? Maybe a nested IF?
    Presumably that's for the MIN version - try this

    =MIN(IF(Criteria_Field=B2,IF(SUBTOTAL(109,OFFSET(Value_Field,ROW(Value_Field)-MIN(ROW(Value_Field)),0,1))>0,Value_Field)))

    still confirmed with CTRL+SHIFT+ENTER

  11. #11
    Registered User
    Join Date
    09-01-2011
    Location
    SK
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Subtotal max/min with IF (urgent help required)

    Quote Originally Posted by SDCh View Post
    Why not use pivot table, you can get all without trouble.
    Unfortunately that won't work for my application. I need it to respond quickly and pivots require a refresh.

  12. #12
    Registered User
    Join Date
    09-01-2011
    Location
    SK
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Subtotal max/min with IF (urgent help required)

    daddylonglegs: Upon further review I can see that it is actually a problem with the min version of the formula. The max works just fine but the min doesn't. My question about filtering out zeroes is actually redundant because I'm handling that with the autofilter. The problem is that the min function is still finding the zeroes which therefore means that it isn't looking at ONLY the filtered set.

    Here's an updated excel sheet:
    Apple-orange-banana filter example.xlsx

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

    Re: Subtotal max/min with IF (urgent help required)

    I don't think you are using exactly the formula I suggested in my last post - try this version in D23

    =MIN(IF(Criteria_Field=A23,IF(SUBTOTAL(109,OFFSET(Value_Field,ROW(Value_Field)-MIN(ROW(Value_Field)),0,1))>0,Value_Field)))

    confirmed with CTRL+SHIFT+ENTER and copy to D24 - I get 2 and 6

  14. #14
    Registered User
    Join Date
    09-01-2011
    Location
    SK
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Subtotal max/min with IF (urgent help required)

    Daddylonglegs: If I could give you +100 I would. Thank you so much!!

+ 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