+ Reply to Thread
Results 1 to 15 of 15

COUNTIFS and SUMIFS with multiple variable choices

  1. #1
    Forum Contributor
    Join Date
    08-28-2015
    Location
    Montreal, Canada
    MS-Off Ver
    2013 on PC, 2011 on MAC
    Posts
    159

    COUNTIFS and SUMIFS with multiple variable choices

    Hey guys and gals.

    I'm trying to write some COUNTIFS and SUMIFS functions with multiple variables choices, but my formulas don't seem to work like I intend them to. And I'm not sure why. Here's an example of what I have:

    Please Login or Register  to view this content.
    The formula "should" return the number of lines that have either "AF" or "A" in 6 different columns of a table called TRACKDIND. However, it doesn't seem to work properly, as soon as I add the second {"AF","A"} criteria.

    Am I missing something ?
    Attached Files Attached Files
    Last edited by KomicJ; 10-10-2019 at 09:49 AM. Reason: Adding a Sample File

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

    Re: COUNTIFS and SUMIFS with multiple variable choices

    I see nothing wrong with the syntax. Maybe there is a flaw in the logic.

    I recommend uploading a small representative sample of your data along with the desired results (which you can enter manually) based on that data.

    To upload an Excel workbook, follow these steps:
    1) Click on "Go Advanced"
    2) Click on "Manage Attachments"
    3) Click on "Choose File"
    4) Choose your file and click on "Open"
    5) Click on "Upload"
    6) Click on "Close this window"

  3. #3
    Forum Contributor
    Join Date
    08-28-2015
    Location
    Montreal, Canada
    MS-Off Ver
    2013 on PC, 2011 on MAC
    Posts
    159

    Re: COUNTIFS and SUMIFS with multiple variable choices

    I added a sample file on the original post.

    The formula I'm trying to work is in cell V4. According to my calculation, the correct return should be 2.

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

    Re: COUNTIFS and SUMIFS with multiple variable choices

    It looks like the formula is counting the number of rows where the selected columns are all "AF" and then adding the number of rows where the selected columns are all "A" instead of counting the number of rows where the selected columns are either "AF" or "A".

    You could use this:

    =COUNTIFS(TRACKDIND[ACHIND],"A*",TRACKDIND[LUNIND],"A*",TRACKDIND[MARIND],"A*",TRACKDIND[MERIND],"A*",TRACKDIND[JEUIND],"A*",TRACKDIND[VENIND],"A*")
    Last edited by 63falcondude; 10-10-2019 at 10:44 AM.

  5. #5
    Forum Contributor
    Join Date
    08-28-2015
    Location
    Montreal, Canada
    MS-Off Ver
    2013 on PC, 2011 on MAC
    Posts
    159

    Re: COUNTIFS and SUMIFS with multiple variable choices

    Quote Originally Posted by 63falcondude View Post
    It looks like the formula is counting the number of rows where the selected columns are all "AF" and then adding the number of rows where the selected columns are all "A" instead of counting the number of rows where the selected columns are either "AF" or "A".

    You could use this:

    =COUNTIFS(TRACKDIND[ACHIND],"A*",TRACKDIND[LUNIND],"A*",TRACKDIND[MARIND],"A*",TRACKDIND[MERIND],"A*",TRACKDIND[JEUIND],"A*",TRACKDIND[VENIND],"A*")
    Yeah, using "A*" could do the trick in this specific case, it would be a nice work around. However, I'm eventually gonna need to use different values for that (such as "AF" or "A" or "N"). So I would be back to square one then.

    So I went another way (posting it here in case someone else is looking for something similar in the future). I'm not that comfortable with SUMPRODUCT, so I'm always hesitant to use it, but I guess it applies here.

    =SUMPRODUCT(((TRACKDIND[ACHIND]="AF")+(TRACKDIND[ACHIND]="A"))*((TRACKDIND[LUNIND]="AF")+(TRACKDIND[LUNIND]="A"))*((TRACKDIND[MARIND]="AF")+(TRACKDIND[MARIND]="A"))*((TRACKDIND[MERIND]="AF")+(TRACKDIND[MERIND]="A"))*((TRACKDIND[JEUIND]="AF")+(TRACKDIND[JEUIND]="A"))*((TRACKDIND[VENIND]="AF")+(TRACKDIND[VENIND]="A")))

    Not sure it's the cleanest way to do it, but returns the right result.

    Thanks for taking the time to look it up. Really appreciated...and rep'd !

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

    Re: COUNTIFS and SUMIFS with multiple variable choices

    I appreciate the rep!

    Honestly, I'm stumped as to why the SUM COUNTIFS formula is acting the way it is.

    SUMPRODUCT will work and you used it correctly. It is just unfortunate that the shorter formula isn't working as we expect it to.

    I'm going to reach out to the community to see if anyone can answer why this isn't working as we expect it to.

    Posting a small representative sample here for others to test on.

    To the community, request is to count the number of rows that are all green (A or AF).
    Attached Files Attached Files
    Last edited by 63falcondude; 10-10-2019 at 11:10 AM.

  7. #7
    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,908

    Re: COUNTIFS and SUMIFS with multiple variable choices

    That array version will only work with two arrays at most, and you have to make sure that one array is orientated oppositely from the other in order to get effectively a cartesian product of outcomes. If they're aligned the same way as here (which is unavoidable with so many), you effectively just get two COUNTIFS added together. In other words, using {"A", "AF"} and {"A"; "AF"} would give you all 4 possible permutations (first array is 'horizontal', second is 'vertical'), whereas {"A", "AF"} and {"A", "AF"} only gives you two combinations ("A" and "A", and "AF" and "AF").
    Rory

  8. #8
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,023

    Re: COUNTIFS and SUMIFS with multiple variable choices

    =SUMPRODUCT(--(MMULT(--((TRACKDIND="AF")+(TRACKDIND="A")),{1;1;1;1;1;1})=6))

    seems to work with 63FD's sample...
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

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

    Re: COUNTIFS and SUMIFS with multiple variable choices

    Quote Originally Posted by Glenn Kennedy View Post
    =SUMPRODUCT(--(MMULT(--((TRACKDIND="AF")+(TRACKDIND="A")),{1;1;1;1;1;1})=6))

    seems to work with 63FD's sample...
    Nice! Although this showed that maybe my sample wasn't as representative as I had originally thought...
    The actual sheet in post #1 has other columns between the ones that need to be included.

  10. #10
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,023

    Re: COUNTIFS and SUMIFS with multiple variable choices

    Yes. see file. There is a "clever" way to populate the series of 1;1;1;1 I just can't recall it right now.
    Attached Files Attached Files

  11. #11
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,023

    Re: COUNTIFS and SUMIFS with multiple variable choices

    This works... but isn't the way I had in mind...


    array entered.
    Attached Files Attached Files

  12. #12
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,023

    Re: COUNTIFS and SUMIFS with multiple variable choices

    Yes!!!!! I remembered.

    No need to array enter this one.

    =SUMPRODUCT(--(MMULT(--((TRACKDIND="AF")+(TRACKDIND="A")),ROW(INDIRECT("1:"&COUNTA(A1:J1)))-ROW(INDIRECT("1:"&COUNTA(A1:J1)))+1)=6))
    Attached Files Attached Files

  13. #13
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,023

    Re: COUNTIFS and SUMIFS with multiple variable choices

    OK, KomicJ.... Finally here it is, on your own sheet.

    =SUMPRODUCT(--(MMULT(--((TRACKDIND[[ACTIND]:[VENIND]]="AF")+(TRACKDIND[[ACTIND]:[VENIND]]="A")),ROW(INDIRECT("1:"&COUNTA(TRACKDIND[[#Headers],[ACTIND]:[VENIND]])))-ROW(INDIRECT("1:"&COUNTA(TRACKDIND[[#Headers],[ACTIND]:[VENIND]])))+1)=6))
    Attached Files Attached Files

  14. #14
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: COUNTIFS and SUMIFS with multiple variable choices

    Quote Originally Posted by Glenn Kennedy View Post
    Yes. see file. There is a "clever" way to populate the series of 1;1;1;1 I just can't recall it right now.
    Glenn FWIW here's another way.

    Replace ROW(INDIRECT("1:"&COUNTA(A1:J1)))-ROW(INDIRECT("1:"&COUNTA(A1:J1)))+1

    With ROW(INDIRECT("1:"&COUNTA(A1:J1)))^0
    Dave

  15. #15
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,023

    Re: COUNTIFS and SUMIFS with multiple variable choices

    Dave. The Force is with you!!

+ 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. SUMIFS/COUNTIFS for multiple conditions/ranges
    By BoudeyCall in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-31-2017, 04:35 PM
  2. SUMIFS/COUNTIFS for multiple conditions/ranges
    By BoudeyCall in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-09-2017, 09:11 PM
  3. [SOLVED] Rules for Multiple Criteria SUMIFS/COUNTIFS and Arrays
    By cmbh in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-12-2016, 08:22 PM
  4. [SOLVED] Countifs and Sumifs for multiple criteria
    By Perk1961 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-15-2015, 02:48 PM
  5. [SOLVED] SUMIFS/COUNTIFS array function question (multiple criteria)
    By akamenov88 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-11-2015, 07:08 PM
  6. Multiple conditions - SumProduct, SumIfs, CountIfs - Which do I need?
    By Carcophan in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-08-2013, 01:43 PM
  7. Sumifs/Countifs with multiple and's and or's
    By falcontrainer in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-19-2013, 01:26 PM

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