+ Reply to Thread
Results 1 to 36 of 36

Sumifs/Max with many conditions

  1. #1
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Sumifs/Max with many conditions

    I have a list of territories in Mexico, along with a unique identifying number and a value attached to it.
    I need the Sumif and / Or Max function (or whatever function will do the job ) to return the highest value of the uniquely identifying account as long as the text WS features in the territory name.

    So for P0009/2018 that would be 492,222
    P00010/2018 would be 1,478,283

    In addition, I would need the formula to ignore all entries with the text "Mexico - Quintana Roo" and "Mexico - Baja California"

    After that I would need the exact same as above, but instead of the text WS to be present I want to isolate those with EQ (so either those with EQ in it on its own or as well as with WS)


    Hope this explains it!

    table.JPG

  2. #2
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Sumifs/Max with many conditions

    Attach example EXCEL file (not a picture, pasted text or any other than Excel format!). This file should be attached to a new post. Never change your original post (except admin's request).

    To attach an Excel file to your post,
    • desensitize data
    • remeber that your example should reflect structure and type of data and contain the result what you want to achieve (manually created if necessary)
    • click Go Advanced,
    • scroll down until you see Manage Attachments,
    • click that and select Browse,
    • select your file and click Open,
    • click Upload and you will see your attachment below Upload Files from a website
    • click Close this window,
    • click Submit reply
    After that you should see attachment in your post

  3. #3
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Sumifs/Max with many conditions

    Try something like this:

    =MAX(IF((A$2:A$12<>"Mexico - Quintana Roo")*(A$2:A$12<>"Mexico - Baja California")*(B$2:B$12="P0009/2018"),C$2:C$12)) Ctrl Shift Enter

    After that I would need the exact same as above, but instead of the text WS to be present I want to isolate those with EQ (so either those with EQ in it on its own or as well as with WS)
    Try something like this:

    =MAX(IF(ISNUMBER(FIND("EQ",A$2:A$12))*(B$2:B$12="P0009/2018"),C$2:C$12)) Ctrl Shift Enter

  4. #4
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Sumifs/Max with many conditions

    I seem unable to upload attachments - it may be blocked by my IT policy.

  5. #5
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Sumifs/Max with many conditions

    Neither of those bring a result for me (ie 0)

    EDIT: your first formula does produce the correct result ( I had to change P0009 to P00009)

    two questions with regards your first formula: Excluding Quintana Roo and Baja is right, but there are other territories in my master list I dont want to include, so just the Mexican territories (which all begin with "Mexico -")
    You specify P0009 in your formula, how is it going to sum up the "max" figure of all the other P number identifiers?
    EDIT: I realise that I havent stated my query well enough, as you are indeed returning the result per line correctly. I should have made it clear that I wanted the SUM of all of the "answers" as it were.
    Last edited by nickmax1; 06-25-2018 at 08:34 AM.

  6. #6
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Sumifs/Max with many conditions

    After reading post #5 I see that what you asked for in post #1 is not the same as what you want.

    but there are other territories in my master list I dont want to include, so just the Mexican territories (which all begin with "Mexico -")
    What is your question here? What about the Mexican territories?

    You specify P0009 in your formula, how is it going to sum up the "max" figure of all the other P number identifiers?
    Are you saying that you want to find the max value for each unique identifier and take the sum of all of those?

    I suggest following the steps in post #2 and uploading a small representative sample workbook along with the desired results (which you can enter manually) based on the sample data.

  7. #7
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Sumifs/Max with many conditions

    Correct, rereading my initial post I wasnt clear. My list of territories are of many countries all over the world. The ones I am interested in summing up are for Mexican territories that are not QR or BC.

    Yes exactly as you put it, find the max value of each unique identifier and take the sum of those.

    I have to get home to upload a representative workbook as it seems the upload document facility is blocked here at work.

  8. #8
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Sumifs/Max with many conditions

    as a quick example (sorry again, i cannot upload documents - only pics) see an example of the numbers the formula should be picking up in yellow, summed up adds up to 12.3m

    It has taken the highest number of every Mexican location within the subset of a unique identifying number that ISNT QR or BC that has the text WS in it.

    EDIT: Made a mistake highlighting two numbers in P00009 - I should have just taken the one with WS in the text

    havent done the same for EQ but the logic is the same.

    table.JPG
    Last edited by nickmax1; 06-25-2018 at 11:34 AM.

  9. #9
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: Sumifs/Max with many conditions

    Quote Originally Posted by nickmax1 View Post
    I seem unable to upload attachments - it may be blocked by my IT policy.
    FYI

    Post a sample spreadsheet with expected results, remove any sensitive data, create a mockup example if necessary.
    Use the Go Advanced option at the bottom of the page then scroll down to Manage Attachments as the "paperclip" method does not work on this forum.
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  10. #10
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Sumifs/Max with many conditions

    here is detailed instruction: post#2

  11. #11
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Sumifs/Max with many conditions

    spreadsheet attached
    Attached Files Attached Files

  12. #12
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Sumifs/Max with many conditions

    Here's one way using 2 helper columns:

    K4 =IF(AND(MAX(IF((C$4:C$30=C4)*(LEFT(B$4:B$30,6)="Mexico")*(ISNUMBER(FIND("WS",B$4:B$30))),D$4:D$30))=D4,COUNTIFS(D$4:D4,D4,C$4:C4,C4)=1),D4,"") Ctrl Shift Enter
    Drag down through K30

    L4 =IF(AND(MAX(IF((C$4:C$30=C4)*(LEFT(B$4:B$30,6)="Mexico")*(ISNUMBER(FIND("EQ",B$4:B$30))),D$4:D$30))=D4,COUNTIFS(D$4:D4,D4,C$4:C4,C4)=1),D4,"") Ctrl Shift Enter
    Drag down through L30

    F4 =SUM(K:K)

    H4 =SUM(L:L)

  13. #13
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Sumifs/Max with many conditions

    thanks! I bow down to your awesome skills...

    is there any way to do this without the need for a helper colomn? also is there a provision in there to exclude all "Mexico - Quintana Roo" and "Mexico - Baja California" entries?

  14. #14
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Sumifs/Max with many conditions

    is there any way to do this without the need for a helper colomn?
    I'm sure there is but unfortunately I can't seem to crack it. I'll see if anyone else can.

    also is there a provision in there to exclude all "Mexico - Quintana Roo" and "Mexico - Baja California"
    Not in the formulas from post #12. You have D15 (the value for "Mexico - Baja California, EQ / WS") highlighted so I figured that you wanted to include it.
    That being said, we can add that in.

    Try these:

    K4:
    Please Login or Register  to view this content.
    Ctrl Shift Enter

    L4:
    Please Login or Register  to view this content.
    Ctrl Shift Enter


    Edit: Thanks for the rep!
    Last edited by 63falcondude; 06-26-2018 at 09:44 AM. Reason: Reputation Added

  15. #15
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Sumifs/Max with many conditions

    Does your real data actually have instances where the value in column B is repeated for a givevn value in column C? The sample workbook doesn't and based on that it appears you could just use this formula:

    =SUMIFS($D$4:$D$30,$B$4:$B$30,"Mexico*WS*",$B$4:$B$30,"<>Mexico - Quintana Roo*",$B$4:$B$30,"<>Mexico - Baja California*")

  16. #16
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Sumifs/Max with many conditions

    Quote Originally Posted by rorya View Post
    Does your real data actually have instances where the value in column B is repeated for a givevn value in column C?
    It does. See D20 and D21 in the workbook from post #11.

    More importantly though, the O.P. is looking to only sum the maximum value for each group in column C, not all values.

    Edit: Whoops. I meant there are duplicate values in columns C and D, not B and C. (Rows 20 and 21)
    Last edited by 63falcondude; 06-26-2018 at 10:08 AM.

  17. #17
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Sumifs/Max with many conditions

    Quote Originally Posted by 63falcondude View Post
    the O.P. is looking to only sum the maximum value for each group in column C, not all values.
    That was the bit I overlooked - I thought it was the max value per territory (there's only one relevant item for each of those).

  18. #18
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Sumifs/Max with many conditions

    There must be a better formula, but this seems to work:

    =SUMPRODUCT((COUNTIFS($C$4:$C$30,$C$4:$C$30,$B$4:$B$30,"Mexico*WS*",$D$4:$D$30,">"&$D$4:$D$30)=0)*(ISNUMBER(SEARCH("Mexico*WS*",$B$4:$B$30)))*(NOT(ISNUMBER(SEARCH("Mexico - Quintana Roo",$B$4:$B$30))))*(NOT(ISNUMBER(SEARCH("Mexico - Baja California",$B$4:$B$30)))),$D$4:$D$30/IF(COUNTIFS($D$4:$D$30,$D$4:$D$30,$C$4:$C$30,$C$4:$C$30,$B$4:$B$30,"Mexico*WS*",$B$4:$B$30,"<>Mexico - Quintana Roo*",$B$4:$B$30,"<>Mexico - Baja California*"),COUNTIFS($C$4:$C$30,$C$4:$C$30,$B$4:$B$30,"Mexico*WS*",$D$4:$D$30,$D$4:$D$30,$B$4:$B$30,"<>Mexico - Quintana Roo*",$B$4:$B$30,"<>Mexico - Baja California*"),1))

  19. #19
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Sumifs/Max with many conditions

    @rorya

    Close! But it includes D21 (because D20 and D21 are both the max for group P00017/2018). Only one max per group should be included.

  20. #20
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Sumifs/Max with many conditions

    Forgot to mention you have to array enter it (so that it excludes the duplicate values!).

  21. #21
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Sumifs/Max with many conditions

    Aah I see. Good job! Rep added.

    Hopefully the O.P. is okay with this solution.

  22. #22
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Sumifs/Max with many conditions

    I'd still go with helper columns personally!

  23. #23
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Sumifs/Max with many conditions

    maybe something like this (just for fun with PowerQuery )
    Attached Files Attached Files

  24. #24
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Sumifs/Max with many conditions

    rorya, your formula worked its magic - thank you so much
    63falcondude and sandy666 thank you so much for your hard work also....

    rep added to you all

  25. #25
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Sumifs/Max with many conditions

    You are welcome and thanks

    Have a nice day

  26. #26
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Sumifs/Max with many conditions

    darn it - it doesnt seem to work on my full listing. Please see attached. I have filtered the data by MEXICO*WS* and highlighted in yellow the numbers I was expected to see summed up in P2. About $9.45m. But the formula produced $6.675m. Where does it go wrong?
    Attached Files Attached Files

  27. #27
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Sumifs/Max with many conditions

    Rorya - have you had a moment to look at my latest problem with the formula?

  28. #28
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Sumifs/Max with many conditions

    It was excluding Baja California Sur as it matched Baja California. Try this one instead:

    =SUMPRODUCT((COUNTIFS($E$4:$E$218,$E$4:$E$218,$D$4:$D$218,"Mexico*WS*",$N$4:$N$218,">"&$N$4:$N$218)=0)*(ISNUMBER(SEARCH("Mexico*WS*",$D$4:$D$218)))*(NOT(ISNUMBER(SEARCH("Mexico - Quintana Roo",$D$4:$D$218))))*(NOT(ISNUMBER(SEARCH("Mexico - Baja California,",$D$4:$D$218)))),$N$4:$N$218/IF(COUNTIFS($N$4:$N$218,$N$4:$N$218,$E$4:$E$218,$E$4:$E$218,$D$4:$D$218,"Mexico*WS*",$D$4:$D$218,"<>Mexico - Quintana Roo*",$D$4:$D$218,"<>Mexico - Baja California,*"),COUNTIFS($E$4:$E$218,$E$4:$E$218,$D$4:$D$218,"Mexico*WS*",$N$4:$N$218,$N$4:$N$218,$D$4:$D$218,"<>Mexico - Quintana Roo*",$D$4:$D$218,"<>Mexico - Baja California,*"),1))

  29. #29
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Sumifs/Max with many conditions

    brilliant that works very well!! The formula works great for the Mexico. I have now run into a problem with applying the logic to New Zealand, where it is to exclude Auckland, Wellington and Canterbury...see attached (last one I promise but I am pulling my hair out trying to solve it!)

    See spreadsheet attached, the formula I have bastardized is in P2...the expected result is in Q2

    where have i gone wrong?
    Attached Files Attached Files

  30. #30
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Sumifs/Max with many conditions

    Where do you get your expected result from? It makes no sense to me.

  31. #31
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Sumifs/Max with many conditions

    Let me try again i think the source data was wrong with the original file.

    I have now highlighted the items I am expecting the formula to pick up, also some comments as to why those numbers are to be used over others.

    hope it makes sense now...
    Attached Files Attached Files

  32. #32
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Sumifs/Max with many conditions

    I'm not seeing any highlights or comments in that file?

  33. #33
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Sumifs/Max with many conditions

    @rorya

    Sorry - uploaded an older version....try this one
    Attached Files Attached Files

  34. #34
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Sumifs/Max with many conditions

    Your data goes down to row 314 but the formula is only looking as far as row 218, that's all.

  35. #35
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Sumifs/Max with many conditions

    @rorya

    a good spot - formula updated but its still short of the expected number.
    Attached Files Attached Files

  36. #36
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Sumifs/Max with many conditions

    There was a logic error. Try this one:

    =SUMPRODUCT((COUNTIFS($E$4:$E$298,$E$4:$E$298,$D$4:$D$298,"New Zealand*",$D$4:$D$298,"<>New Zealand - Auckland",$D$4:$D$298,"<>New Zealand - Canterbury, Christchurch",$D$4:$D$298,"<>New Zealand - Wellington, Hutt/Porirua",$N$4:$N$298,">"&$N$4:$N$298)=0)*(ISNUMBER(SEARCH("New Zealand*",$D$4:$D$298)))*(NOT(ISNUMBER(SEARCH("New Zealand - Auckland",$D$4:$D$298))))*(NOT(ISNUMBER(SEARCH("New Zealand - Canterbury, Christchurch",$D$4:$D$298))))*(NOT(ISNUMBER(SEARCH("New Zealand - Wellington, Hutt/Porirua",$D$4:$D$298)))),$N$4:$N$298/IF(COUNTIFS($N$4:$N$298,$N$4:$N$298,$E$4:$E$298,$E$4:$E$298,$D$4:$D$298,"New Zealand*",$D$4:$D$298,"<>New Zealand - Auckland",$D$4:$D$298,"<>New Zealand - Canterbury, Christchurch",$D$4:$D$298,"<>New Zealand - Wellington, Hutt/Porirua"),COUNTIFS($E$4:$E$298,$E$4:$E$298,$D$4:$D$298,"New Zealand*",$N$4:$N$298,$N$4:$N$298,$D$4:$D$298,"<>New Zealand - Auckland",$D$4:$D$298,"<>New Zealand - Canterbury, Christchurch",$D$4:$D$298,"<>New Zealand - Wellington, Hutt/Porirua"),1))

    Once again, I would really recommend rethinking this approach. A pivot table would probably help speed things up!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. nested sumifs after first two if conditions are met
    By Shruder in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-21-2018, 05:30 PM
  2. sumifs with multiple conditions
    By cpg_123 in forum Excel General
    Replies: 9
    Last Post: 07-20-2016, 01:31 PM
  3. SUMIFS with multiple conditions
    By AadVissers in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-21-2016, 12:22 PM
  4. SUMIFS with AND conditions; between two dates
    By dchubbock in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-08-2016, 06:36 PM
  5. Sumifs multiple conditions
    By ksmith21 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-16-2015, 06:12 AM
  6. [SOLVED] SUMIFS with OR conditions
    By morbdetro in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-12-2013, 01:01 PM
  7. SumIfs in VBA with two conditions for one range
    By Ivkosky in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-24-2013, 10:04 AM

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