+ Reply to Thread
Results 1 to 18 of 18

Modification to COUNTIFS formula

  1. #1
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Modification to COUNTIFS formula

    Is there a way to change this formula so that it will only calculate the COUNTIFS on data that falls in the month of May? The dates in the data set are in the range V14:V100000


    =SUM(COUNTIFS($Q$14:$Q$10000,{"ii1x2","ii1x3","ii1x4","ii1x5","ii1x6","ii1x7","ii1x8","ii1x9","ii1x10"},$K$14:$K$10000,{">0"}))
    Last edited by rhudgins; 06-16-2011 at 12:27 PM.

  2. #2
    Valued Forum Contributor Miraun's Avatar
    Join Date
    04-03-2009
    Location
    New England
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    554

    Re: Modification to COUNTIFS formula

    =SUM(IF(MONTH(V14:V100000)=5,1,0))

    Array formula, enter the above and then use Control, Shift, Enter.
    Going for Guru! Click the Star to the bottom left of this post if I helped!

  3. #3
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Re: Modification to COUNTIFS formula

    Thank you but I would like to incorporate that formula into the formula that I initially posted. How can this be done?

  4. #4
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191

    Re: Modification to COUNTIFS formula

    I think you'd have to change it to a Sumproduct formula. Countifs can't manipulate the data in ranges.
    =Sumproduct(($Q$14:$Q$10000={"ii1x2","ii1x3","ii1x4","ii1x5","ii1x6","ii1x7","ii1x8","ii1x9","ii1x1 0"})*($K$14:$K$10000>0)*(Month($V$14:$V$100000)=5)) should work, I think.
    Life is about perseverance. Remember: today's mighty oak tree is just yesterday's nut that held its ground.

    If you like a post, please rate it with the scales icon (top right).
    If you feel really indebted, please consider a donation to charity, such as Feed the Children or Habitat for Humanity.

  5. #5
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Re: Modification to COUNTIFS formula

    That formula is producing a #N/A error. Any idea why? Here is a copy of my workbook. The formula is in AP12
    Attached Files Attached Files

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

    Re: Modification to COUNTIFS formula

    All ranges have to be the same size - last range needs to be 10000 not 100000, i.e.

    =SUMPRODUCT(($Q$14:$Q$10000={"ii1x2","ii1x3","ii1x4","ii1x5","ii1x6","ii1x7","ii1x8", "ii1x9","ii1x10"})*($K$14:$K$10000>0)*(MONTH($V$14:$V$10000)=4))

    You can modify your COUNTIFS approach but you need to add two more criteria, i.e.

    =SUM(COUNTIFS($Q$14:$Q$10000,{"ii1x2","ii1x3","ii1x4","ii1x5","ii1x6","ii1x7","ii1x8","ii1x9","ii1x10"},$K$14:$K$10000,">0",$V$14:$V$10000,">="&DATE(2011,4,1),$V$14:$V$10000,"<="&DATE(2011,4,30)))

    The first formula will count April dates in any year, the second is restricted to 2011
    Audere est facere

  7. #7
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191

    Re: Modification to COUNTIFS formula

    The range you used in V had one too many zeroes and I didn't catch the error when I inserted into the formula. Make it go through V10000 instead and it comes up with 8.

  8. #8
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191

    Re: Modification to COUNTIFS formula

    For my own edification, which would be faster, adding two criteria to the Countifs or changing to Sumproduct?

  9. #9
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,757

    Re: Modification to COUNTIFS formula

    Without testing I suspect that COUNTIFS will be faster, typically a COUNTIF/COUNTIFS formula can be 5-10 times faster than the equivalent SUMPRODUCT.....

  10. #10
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Re: Modification to COUNTIFS formula

    Thank you for pointing out that error to me. How would I add the same month adjustment to thisSUMIFS formula? Would it be the same idea?

    =SUM(SUMIFS($K$14:$K$10000,$Q$14:$Q$10000,{"ii1x2","ii1x3","ii1x4","ii1x5","ii1x6","ii1x7","ii1x8","ii1x9","ii1x10"}))

  11. #11
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,757

    Re: Modification to COUNTIFS formula

    Yes you can add date ranges exactly as I did with the COUNTIFS version

    ....btw, are you counting all instances of values beginning with "ii1x" in column Q....or are there instances that don't appear in the list like ii1x1 or ii1x22?

  12. #12
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Re: Modification to COUNTIFS formula

    Is there a way to use the SUMPRODUCT formula?

  13. #13
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Re: Modification to COUNTIFS formula

    Yes, there are instances other then ii1x that don't appear in the list

  14. #14
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,757

    Re: Modification to COUNTIFS formula

    Quote Originally Posted by rhudgins View Post
    Is there a way to use the SUMPRODUCT formula?
    Almost exactly the same as the other one: This was the original

    =SUMPRODUCT(($Q$14:$Q$10000={"ii1x2","ii1x3","ii1x4","ii1x5","ii1x6","ii1x7","ii1x8", "ii1x9","ii1x10"})*($K$14:$K$10000>0)*(MONTH($V$14:$V$10000)=4))

    just remove >0

  15. #15
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Re: Modification to COUNTIFS formula

    Removing >0 is producing a #VALUE error. Below, I constructed this SUMIFS formula using the COUNTIFS example that you gave me above. What would the equivalent SUMPRODUCT formula be to calculate the same result? The reason I ask is because I want to avoid having to constantly change the date ranges inside the SUMIFS formula

    =SUM(SUMIFS($K$14:$K$10000,$Q$14:$Q$10000,{"ii1x2","ii1x3","ii1x4","ii1x5","ii1x6","ii1x7","ii1x8","ii1x9","ii1x1 0"},$V$14:$V$10000,">="&DATE(2011,6,1),$V$14:$V$10000,"<="&DATE(2011,6,30)))
    Last edited by rhudgins; 06-15-2011 at 04:42 PM.

  16. #16
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Re: Modification to COUNTIFS formula

    DaddyLongLegs: Can you please help me with this?

  17. #17
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,757

    Re: Modification to COUNTIFS formula

    OK, I took a closer look.....

    normally the SUMPRODUCT would work but in column K because you have some formulas returning "" those are treated as text and they cause #VALUE! errors in that formula.

    3 options

    1) Leave the data "as is" and use this "array formula"

    =SUM(IF(($Q$14:$Q$10000={"ii1x2","ii1x3","ii1x4","ii1x5","ii1x6","ii1x7","ii1x8","ii1x9","ii1x10"})*(MONTH($V$14:$V$10000)=4),$K$14:$K$10000))

    confirmed with CTRL+SHIFT+ENTER

    2) Change the formula in K14 copied down to this

    =IF(D14="",0,J14+D14)

    and then the SUMPRODUCT version will work for you, i.e.

    =SUMPRODUCT(($Q$14:$Q$10000={"ii1x2","ii1x3","ii1x4","ii1x5","ii1x6","ii1x7","ii1x8","ii1x9","ii1x10"})*($K$14:$K$10000)*(MONTH($V$14:$V$10000)=4))

    [If you want to display a blank rather than $0 just custom format to do so]

    3) You can use the SUMIFS formula with a reference to a cell, e.g. put the first of the month in Z2 and use this version

    =SUM(SUMIFS($K$14:$K$10000,$Q$14:$Q$10000,{"ii1x2","ii1x3","ii1x4","ii1x5","ii1x6","ii1x7","ii1x8"," ii1x9","ii1x1 0"},$V$14:$V$10000,">="&Z2,$V$14:$V$10000,"<="&EOMONTH(Z2,0)))

    Now you only need to change a single date

  18. #18
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Re: Modification to COUNTIFS formula

    Thank you for taking the time to give me these different solutions. I am going to go with the array formula because it will easily allow me to reference the month # in a different cell. Thank you for your help

+ 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