+ Reply to Thread
Results 1 to 14 of 14

Count IF formula help

  1. #1
    Registered User
    Join Date
    09-13-2012
    Location
    GA, USA
    MS-Off Ver
    2010
    Posts
    48

    Count IF formula help

    Hi,

    In the attached sheet I want to enter a CountIF formula based on entries in Column A, B, C...

    - In Column F, return the count of ID (only first entry) by month
    - In Column G, return the count of PASS (only first entry) by month
    - In Column H, return the count of FAIL(only first entry) by month

    Thanks much all.
    Attached Files Attached Files

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

    Re: Count IF formula help

    What do you mean by "only first entry"? If you were counting only the first entry, the count would be 1.

    If you mean to count the number of unique ID's in each month, you can use this in F2:

    =SUM(--(FREQUENCY(IF(TEXT(A$2:A$18,"mmmm")=E2,MATCH(B$2:B$18,B$2:B$18,0)),ROW(B$2:B$18)-ROW(B2)+1)>0)) Ctrl Shift Enter

    Your conditional formatting and manually entered values (in column F) are looking at duplicates regardless of the month that they are in.

    A more appropriate conditional formatting can be applied like this:

    Highlight B2:B18 > Conditional Formatting > New Rule > Use a formula
    =COUNTIFS(A:A,">"&EOMONTH(A2,-1),A:A,"<="&EOMONTH(A2,0),B:B,B2)>1
    Format: Fill color of your choice > OK > OK

    I don't understand how you came to the numbers that are in columns G and H.

    Also, keep in mind that you do not have any years in column E so this will work reliably when there is only one year in column A (like in your sample).
    Last edited by 63falcondude; 01-07-2019 at 10:11 AM.

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

    Re: Count IF formula help

    I'll assume the manually entered values were mistakes.

    You can use a helper column, let's say in column M using this formula in M2:
    =COUNTIFS(A$2:A2,">"&EOMONTH(A2,-1),A$2:A2,"<="&EOMONTH(A2,0),B$2:B2,B2)

    Then you can use this formula in G2:
    =SUMPRODUCT((TEXT($A$2:$A$18,"mmmm")=$E2)*($C$2:$C$18=G$1)*($M$2:$M$18=1))
    and drag it over and down.

  4. #4
    Registered User
    Join Date
    09-13-2012
    Location
    GA, USA
    MS-Off Ver
    2010
    Posts
    48

    Re: Count IF formula help

    So,

    for Column F, I only want to count entries which has occurred the first time but if that entry is already present in the past date then it should not count it.
    for Column G, count the number of PASS from Column C (disregard the respective ID, that is not counted due to previous entry)
    for Column H, count the number of FAIL from Column C (disregard the respective ID, that is not counted due to previous entry)

    Disregard the Conditional formatting, I just did it to help manual counting.
    I have fixed the column E to include Month & Year

    Thanks!!
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: Count IF formula help

    My suggestion is VBA - Your last attachment.
    Please Login or Register  to view this content.
    Greetings.
    Last edited by maras_mak; 01-07-2019 at 11:27 AM.

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

    Re: Count IF formula help

    My previous answers still apply. The only difference is accounting for the year now.

    That is:

    F2 =SUM(--(FREQUENCY(IF((A$2:A$18>=E2)*(A$2:A$18<=EOMONTH(E2,0)),MATCH(B$2:B$18,B$2:B$18,0)),ROW(B$2:B$18)-ROW(B2)+1)>0)) Ctrl Shift Enter
    Drag down through F4.

    (Helper column) M2 =COUNTIFS(A$2:A2,">"&EOMONTH(A2,-1),A$2:A2,"<="&EOMONTH(A2,0),B$2:B2,B2)
    Drag down through M18.

    G2 =SUMPRODUCT(($A$2:$A$18>EOMONTH($E2,-1))*(($A$2:$A$18<=EOMONTH($E2,0)))*($C$2:$C$18=G$1)*($M$2:$M$18=1))
    Drag over to H2 then down through row 4.

  7. #7
    Registered User
    Join Date
    09-13-2012
    Location
    GA, USA
    MS-Off Ver
    2010
    Posts
    48

    Re: Count IF formula help

    I tried using the formula, I see for the month of November the count is returning as '6' instead of '5'.
    I have manually counted the entries in Column I to compare.

    11/04/18 100697 (count)
    11/15/18 100257A (count)
    11/16/18 100546 (count)
    11/20/18 100257A (do not count)
    11/26/18 100602 (count)
    11/27/18 100397B (count)
    11/30/18 641881 (do not count)
    Attached Files Attached Files

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

    Re: Count IF formula help

    Why should cell B14, 641881, not be counted for November?

  9. #9
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Count IF formula help

    Please try

    F2
    =SUMPRODUCT((TEXT($A$2:$A$18,"mmmm")=E2)*(MATCH($B$2:$B$18,$B$2:$B$18,)=ROW($A$2:$A$18)-ROW($A$1)))

    G2 copy to H2
    =SUMPRODUCT((TEXT($A$2:$A$18,"mmmm")=$E2)*(MATCH($B$2:$B$18,$B$2:$B$18,)=ROW($A$2:$A$18)-ROW($A$1))*($C$2:$C$18=G$1))

    copy F2:H2 down
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    09-13-2012
    Location
    GA, USA
    MS-Off Ver
    2010
    Posts
    48

    Re: Count IF formula help

    @maras_mak - thanks for the VBA but I prefer solving using formula

    @63falcondude - 641881 in Cell B14 is already entered in Cell B6, hence do not count

    @Bo_Ry - I tried your formula, it worked for my initial posted file but then I changed the format of Column E from TEXT to DATE to capture both month and year. So now your formula is not giving me correct solution. See updated attached file.
    Attached Files Attached Files

  11. #11
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Count IF formula help

    Please try
    F2
    =SUMPRODUCT((TEXT($A$2:$A$18,"myy")=TEXT(E2,"myy"))*(MATCH($B$2:$B$18,$B$2:$B$18,)=ROW($A$2:$A$18)-ROW($A$1)))

    G2 copy to H2
    =SUMPRODUCT((TEXT($A$2:$A$18,"myy")=TEXT($E2,"myy"))*(MATCH($B$2:$B$18,$B$2:$B$18,)=ROW($A$2:$A$18)-ROW($A$1))*($C$2:$C$18=G$1))
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    09-13-2012
    Location
    GA, USA
    MS-Off Ver
    2010
    Posts
    48

    Re: Count IF formula help

    It worked fine, but can I extend this formula to not just 18 rows? Keep in mind data in Column A, B, C will be empty after row 18 for now but it will keep populating periodically. I tried 500 columns like below but gave me an error.

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  13. #13
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Count IF formula help

    Try this

    F2
    =SUMPRODUCT((TEXT($A$2:$A$2000,"myy")=TEXT($E2,"myy"))*(MATCH($B$2:$B$2000&"",INDEX($B$2:$B$2000&"",),)=ROW($A$2:$A$2000)-ROW($A$1)))

    G2 copy to H2
    =SUMPRODUCT((TEXT($A$2:$A$2000,"myy")=TEXT($E2,"myy"))*(MATCH($B$2:$B$2000&"",INDEX($B$2:$B$2000&"",),)=ROW($A$2:$A$2000)-ROW($A$1)*($C$2:$C$2000=G$1)))

  14. #14
    Registered User
    Join Date
    09-13-2012
    Location
    GA, USA
    MS-Off Ver
    2010
    Posts
    48

    Re: Count IF formula help

    Worked great Bo_Ry, thanks a lot.

+ 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. Formula Required to Count Rows only if condition is meet or else dont count
    By Shahbazk in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-22-2017, 08:39 AM
  2. (Count Formula) Count if two seperate ranges create unique combination
    By Geekcrux in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-10-2016, 07:00 AM
  3. Formula to count number of visible rows, and formula to count visible blanks
    By radoncadonc in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-28-2015, 04:19 PM
  4. [SOLVED] Count formula not count hidden cells in table
    By tlacloche in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-06-2013, 02:35 PM
  5. [SOLVED] Count and average formula needed to not count text field
    By excelteam777 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-07-2013, 05:30 PM
  6. Replies: 5
    Last Post: 08-29-2012, 05:25 PM
  7. Count Formula-Would this be a good example to use the count function?
    By JK1234 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 08-01-2008, 02:44 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