+ Reply to Thread
Results 1 to 8 of 8

Using SUMPRODUCT in place of COUNTIFS for multi column lookup

  1. #1
    Registered User
    Join Date
    12-04-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    79

    Using SUMPRODUCT in place of COUNTIFS for multi column lookup

    Hi guys.

    All help HUGELY appreciated

    I have a table:
    A - B - C - D
    Date - Name 1 - Name 2 - Fruit
    1/2/2014 - Steve - Simon - Apple
    2/3/2014 - Mark - Steve - Pear
    10/3/2014 - Steve - Mark - Apple
    1/2/2015 - Simon - Steve - Pear

    I want a formula that will tell me how many times Steve's name appears in columns B or C during 2014 where the fruit is Apple = 2
    IF there was only one column of names then I could do it easily with a COUNTIFS(A:A,>=date,A:A,<=date,B:B,"Simon",D:D,"Apple")

    I think I need to replace the COUNTIFS with SUMPRODUCT, but I cant work out how to do it.

    The formula features of "Steve", "Apple" and "Date" can either be hard written into the formula OR can reference another cell like (E1), I don't mind.

    Thanks so much. The few trial and errors that I attempted failed entirely and you guys are always so knowledgeable.

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Using SUMPRODUCT in place of COUNTIFS for multi column lookup

    Maybe -

    =SUMPRODUCT((YEAR($A$2:$A$5)=2014)*($B$2:$B$5="Steve")*($D$2:$D$5="Apple")+(YEAR($A$2:$A$5)=2014)*($C$2:$C$5="Steve")*($D$2:$D$5="Apple"))
    I have hardcoded 2014, Steve & Apple. you can have them in cells aswell
    Cheers!
    Deep Dave

  3. #3
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Using SUMPRODUCT in place of COUNTIFS for multi column lookup

    hi there. do upload an excel sample so that we do not have to manually key in your data to do a testing.

    input the desired results so that we don't have to second-guess if what we are doing is correct or not. you may look at my signature to upload an eg that is easier to understand. i can see that you have done that

    the upload attachment must be done by going to Go Advanced. click on Manage Attachments. Choose file, upload and close the window.

    if i really guessed it wrongly, please upload something according to my recommendations. try to use the solution i have given and we'll help to advise what went wrong.

    try:
    =SUMPRODUCT(((B3:B6="Steve")+(C3:C6="Steve")>0)*(YEAR(A3:A6)=2014)*(D3:D6="Apple"))

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,152

    Re: Using SUMPRODUCT in place of COUNTIFS for multi column lookup

    Try

    =SUMPRODUCT(--(B2:C10="Steve")*(D2:D10="Apple")*(YEAR(A2:A10)=2014))
    Last edited by JohnTopley; 01-12-2018 at 05:25 AM.

  5. #5
    Registered User
    Join Date
    12-04-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    79

    Re: Using SUMPRODUCT in place of COUNTIFS for multi column lookup

    Thanks everyone.
    Almost there.
    All formula options work IF I replace
    *(YEAR(A2:A10)=2014))
    with
    A:A>1/1/2014

    When I use the YEAR function I get a #VALUE error come back.

    Why might that be?

    Is there a way to remove the YEAR function and replace it with 'Greater than 1/1/2014 and less than 31/12/2014' ??

    (Would have uploaded an example BUT was told in another thread that it is better to write it into the thread than to use uploads as it is more helpful for people searching for similar answers as it shows up in search engines this way.)

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,152

    Re: Using SUMPRODUCT in place of COUNTIFS for multi column lookup

    Try

    =SUMPRODUCT(--(B2:C10="Steve")*(D2:D10="Apple")*(A2:A10)>="Startdate")*(A2:A10)<="Enddate"))

    Startdate/Enddate are cells with your dates

  7. #7
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Using SUMPRODUCT in place of COUNTIFS for multi column lookup

    Quote Originally Posted by RoundaboutCJP View Post
    IF I replace
    *(YEAR(A2:A10)=2014))
    with
    A:A>1/1/2014

    When I use the YEAR function I get a #VALUE error come back.

    Why might that be?
    Most likely because you have a TEXT string in one of the cells, like a Header value in A1.

    It's highly recommended to NOT use entire column references like A:A in a sumproduct formula.
    Because sumproduct will perform it's functions on every single cell in the column, even the blank ones.
    This creates 'alot' of unnecessary work, reducing sheet performance.

    Restrict your ranges to the actual used area, and exlude the header row.

  8. #8
    Registered User
    Join Date
    12-04-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    79

    Re: Using SUMPRODUCT in place of COUNTIFS for multi column lookup

    Ah ha. Thatll be it - column headers.
    THanks for the advice and thanks all for the solutions!

+ 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. [SOLVED] Sumproduct to replace countifs as countifs don't work on external source reference
    By KrishnaSagar in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-02-2017, 02:33 AM
  2. =COUNTIFS and Multi-Column Exceptions
    By ajpl in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-27-2017, 05:52 PM
  3. [SOLVED] Using SUMPRODUCT(COUNTIFS(...)) to add values based on a lookup table
    By HeyInKy in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-29-2016, 04:11 PM
  4. [SOLVED] Multi-Column Lookup of A formula
    By cmore in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 08-11-2015, 02:05 PM
  5. multi-column language lookup
    By moschen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-10-2009, 10:47 AM
  6. multi-column comparison and lookup
    By 7starmantis in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-21-2009, 11:55 AM
  7. Replies: 6
    Last Post: 02-21-2009, 08:13 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