+ Reply to Thread
Results 1 to 21 of 21

Countif Month and another value match

  1. #1
    Registered User
    Join Date
    12-05-2014
    Location
    UK
    MS-Off Ver
    Office 2010
    Posts
    18

    Countif Month and another value match

    I'm trying to build a formula which will count the amount of entries that match 2 criteria, the first that matches a month and the second which states either "Late" or "OK".

    I get an #NAME? message when I use this formula =SUMPRODUCT(($C$2:$C$200=Late)*($D$2:$D$200=(MONTH($D$2:$D$200)=11)))

    Can anyone help please

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Countif Month and another value match

    Without seeing your data. Late needs to be in quotes "late"
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    12-05-2014
    Location
    UK
    MS-Off Ver
    Office 2010
    Posts
    18

    Re: Countif Month and another value match

    Thanks ChemistB

    Capture.jpg

    That's a screenshot of my data. I want it count how many entries match late or ok per month. I've tried your suggestion about the quote marks, but it just returns 0, when it should be 3
    Attached Images Attached Images

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Countif Month and another value match

    I can't see screenshots for some reason. You'd need to upload an example workbook (Go Advanced>Manage Attachments)

  5. #5
    Registered User
    Join Date
    12-05-2014
    Location
    UK
    MS-Off Ver
    Office 2010
    Posts
    18

    Re: Countif Month and another value match

    DRAFT.xlsx

    Ok, thanks. I've attached it now...

  6. #6
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Countif Month and another value match

    Try this.. will definitely do the job..
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Regards,
    Vikas Gautam
    Excel-buzz.blogspot.com

    Excel is not a matter of Experience, its a matter of Application.

    Say Thanks, Click * Add Reputation

  7. #7
    Registered User
    Join Date
    12-05-2014
    Location
    UK
    MS-Off Ver
    Office 2010
    Posts
    18

    Re: Countif Month and another value match

    Thanks Vikas, that works for the Late entry.

    I've tried it for the OK entry, but it doesn't work correct. I've just swapped "Late" for "OK", would that be the correct way to do it?

  8. #8
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Countif Month and another value match

    Quote Originally Posted by ooberandy View Post
    Thanks Vikas, that works for the Late entry.

    I've tried it for the OK entry, but it doesn't work correct. I've just swapped "Late" for "OK", would that be the correct way to do it?
    Hi I'm late to this party, but I'll answer that question for you.

    The answer is yes, but if it's not working then I'll point a couple of things out.
    The quotes " " in the formula are not optional, they must be there, if you changed the formula part from "Late" to OK without the quotes it won't work.

    The same goes for the "*11*" if you changed that to a different number, say 12 it has to look like this. "*12*". Another issue would be that either the OK in your table or the OK you typed in the formula are different. If you accidently have a space in either your table or in your formula you will have a problem. This happens sometime and it's hard to catch. I would suggest copying and pasting one of the OK from you table and paste it into the formula just to make sure Excel is looking at the same thing.

    The last thing I noticed was that in your attachment the date format of the dates in the D column are dd/mm/yyyy and those that are in the G column show as for example Jan-15 the underlying number was entered as 1/1/2015 which could be a d/m/y format but those for other months like March are 3/1/2015 which leads me to believe they are in a US format. So the reason I'm bringing this up is if you are trying to incorporate those cells into your formula to look at the C column you are going to have an issue.

    Good Luck.

  9. #9
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Countif Month and another value match

    Use following to be more precise
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Yes Using OK and 11 Combination will return 0 because there is no such combination in your data.
    Read your data carefully you will get to know what I mean. However, formula is correct for what you meant.

  10. #10
    Banned User!
    Join Date
    10-29-2012
    Location
    Europe
    MS-Off Ver
    2013, 2016
    Posts
    318

    Re: Countif Month and another value match

    Use this formula for "Late"
    =SUMPRODUCT(($C$2:$C$37="Late")*((MONTH($D$2:$D$37)=MONTH(G2))*(YEAR($D$2:$D$37)=YEAR(G2))))
    and this for "OK"
    =SUMPRODUCT(($C$2:$C$37="OK")*((MONTH($D$2:$D$37)=MONTH(G2))*(YEAR($D$2:$D$37)=YEAR(G2))))

  11. #11
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Countif Month and another value match

    Quote Originally Posted by Indi_Ra View Post
    Use this formula for "Late"
    =SUMPRODUCT(($C$2:$C$37="Late")*((MONTH($D$2:$D$37)=MONTH(G2))*(YEAR($D$2:$D$37)=YEAR(G2))))
    and this for "OK"
    =SUMPRODUCT(($C$2:$C$37="OK")*((MONTH($D$2:$D$37)=MONTH(G2))*(YEAR($D$2:$D$37)=YEAR(G2))))
    See my post #8 above regarding the dates in column D versus the dates in column G.

    When you open the file look at the underlying entries for column G versus those for column D, are they different when you look at them.

    On my computer they are entered two different ways and your formula doesn't work because of that?

    What about you, can you just plug the formula in and have it work on the posted file?

  12. #12
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Countif Month and another value match

    Any formula where you treat the date as a number will not work because ooberandy's dates are entered as text.

    Vikas's second solution is best as the first one could give faulty values on the 11th of any month.

    If you want to stick with SUMPRODUCT (you shouldn't, Vikas's solution is more efficient)

    =SUMPRODUCT(($C$2:$C$200="Late")*(ISNUMBER(SEARCH("/11/",$D$2:$D$200))))
    =SUMPRODUCT(($C$2:$C$200="OK")*(ISNUMBER(SEARCH("/11/",$D$2:$D$200))))
    Hope that helps.

  13. #13
    Banned User!
    Join Date
    10-29-2012
    Location
    Europe
    MS-Off Ver
    2013, 2016
    Posts
    318

    Re: Countif Month and another value match

    Quote Originally Posted by skywriter View Post
    See my post #8 above regarding the dates in column D versus the dates in column G.

    When you open the file look at the underlying entries for column G versus those for column D, are they different when you look at them.

    On my computer they are entered two different ways and your formula doesn't work because of that?

    What about you, can you just plug the formula in and have it work on the posted file?


    In column D and G are real data (numbers) but formatted differently. Therefore, we extracted the month and year (different days but no matter) in columns D and G and count how many "Late" or "OK" correspond to these months and years.
    The formulas we checked in Attachment OP and it works.

    In column G are also different years and I used it formula "drag" down, it works.
    Last edited by Indi_Ra; 01-30-2015 at 04:02 PM.

  14. #14
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Countif Month and another value match

    Here is something (untested) that could work for you

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  15. #15
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Countif Month and another value match

    Quote Originally Posted by Indi_Ra View Post
    In column D and G are real data (numbers) but formatted differently. Therefore, we extracted the month and year (different days but no matter) in columns D and G and count how many "Late" or "OK" correspond to these months and years.
    The formulas we checked in Attachment OP and it works.

    In column G are also different years and I used it formula "drag" down, it works.
    That's interesting because when I open the file from post #5 and I type in a blank cell =ISNUMBER(D11) I get FALSE which seems to support what Chemist is saying in Post #12 that these are not numbers. When I type = ISNUMBER(G7) I get TRUE. If I try the month or year function on cell D11, I get #VALUE!. I'm not sure how it's working for you.

  16. #16
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Countif Month and another value match

    Column D contains values that are not numbers. However the correct day, month or year is extracted when using DAY, MONTH or YEAR functions. If the month is being correctly identified in column D and in column G then it doesn't matter whether they are both numbers or not for the calculation. =MONTH(D2)=MONTH(G2) returns TRUE.


    The formula that I gave in $14 does appear to work when column D has the same number of values as the rest of the table.

  17. #17
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Countif Month and another value match

    Quote Originally Posted by newdoverman View Post
    Column D contains values that are not numbers. However the correct day, month or year is extracted when using DAY, MONTH or YEAR functions. If the month is being correctly identified in column D and in column G then it doesn't matter whether they are both numbers or not for the calculation. =MONTH(D2)=MONTH(G2) returns TRUE.


    The formula that I gave in $14 does appear to work when column D has the same number of values as the rest of the table.
    Not on my computer, I get #VALUE!
    =MONTH(D2)=MONTH(G2) returns TRUE

    When I type
    =MONTH(D10)=MONTH(D11)
    Which are the same exact entries 16/01/2015 I get value again.

    When I type
    =YEAR(G6)=YEAR(G5) I get TRUE.

  18. #18
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Countif Month and another value match

    This may be of interest. I don't get the #Value error.
    Attached Files Attached Files

  19. #19
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Countif Month and another value match

    Quote Originally Posted by newdoverman View Post
    This may be of interest. I don't get the #Value error.
    Not working for me and I'm wondering why? The resultant values of your formula looked good until I changed the cell reference to a different cell and then I got #VALUE, changing back to the original reference doesn't fix anything.

    Okay on a hunch I figured out what the issue is my default date format is US mm/dd/yyyy.
    I changed it to dd/mm/yyyy and the formulas perked right up and worked.

    Well thanks for the education. Usually when I deal with helping somebody with different date formats I just enter the data by spelling out the month the days are obvious and I use the 4 digit year.

    Well this was an education, thank for that, I was thinking you were going to figure I was trying to be obnoxious, but it wasn't working for me. Now I'm going to switch my date back and watch the formulas fail, but I learned something and I appreciate it.

    Thanks,
    Bruce

  20. #20
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Countif Month and another value match

    Obnoxious.....not at all. having a problem.....maybe trying to help....positively.

    I'm happy to have been of some help. All of us are always learning

    When dates don't work for me with a downloaded Excel file, I select the cells and change the formatting to GENERAL if the dates change to serial numbers then I know that I am dealing with real dates even though the format may be different. The idea of spelling out the date makes perfect sense to me as it takes the confusion out of date formats.

  21. #21
    Registered User
    Join Date
    12-05-2014
    Location
    UK
    MS-Off Ver
    Office 2010
    Posts
    18

    Re: Countif Month and another value match

    Thanks for all you replies, I really appreciate all your help.

    Indi_Ra's is the only formula that works for me though, so I'll stick with that.

    Thanks

+ 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. Replies: 18
    Last Post: 09-08-2014, 05:06 PM
  2. Excel 2007 : COUNTIF and MONTH
    By john_mk in forum Excel General
    Replies: 1
    Last Post: 04-13-2012, 10:23 AM
  3. Replies: 2
    Last Post: 03-16-2012, 12:03 PM
  4. Countif during a month
    By Beowulfe in forum Excel General
    Replies: 5
    Last Post: 11-05-2011, 08:48 AM
  5. CountIf by month
    By ashley0578 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-14-2006, 07:00 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