+ Reply to Thread
Results 1 to 21 of 21

Count formula

Hybrid View

  1. #1
    Registered User
    Join Date
    04-29-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    53

    Count formula

    Hello,

    i need help in counting the cells between 2 dates, and condition is- to count cells in Column "G" if the same name listed more than once in the given period. This formula counts duplicate names.
    =IF(AND(H2>=EDATE(A2,-1),COUNTIF($G$2:G2,G2),H2<=EOMONTH(EDATE(A2,-1),0)),1,0)

    Thank you.

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

    Re: Count formula

    Can you post an example workbook? (Go Advanced>Manage Attachments)
    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
    04-29-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Count formula

    Please see my file. Sheet "O_D" has highlighted cells with duplicate counts.
    Attached Files Attached Files

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

    Re: Count formula

    Okay, so Michelle in row 2 reappears again in rows 12 and 13. So in row 2 (what column?) you want to return 10 (12-2) or are we counting inclusive so 11? Then on row 12, we'd return a 1 or 2? Am I on the right track?

  5. #5
    Registered User
    Join Date
    04-29-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Count formula

    If the same name, tha same dates range "1" should be only once, another cell empty.
    So, cells P4, P20; O9, O13, O17 should be empty.

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

    Re: Count formula

    Okay, some comments, In O2 copied down, you have

    =IF(AND(H2>=EDATE(A2,-1),COUNTIF($G$2:G2,G2),H2<=EOMONTH(EDATE(A2,-1),0)),1,0)

    The middle term (COUNTIF($G$2:G2,G2)) will always be true. Do you mean to use COUNTIF($G$2:G2,G2)=1?

    Anyway, to prevent a second visit within the same month as showing up as a 1, try this in O2 and P2

    =IF(SUMPRODUCT(($G$2:$G2=G2)*($A$2:$A2=$A2))>1, 0, IF(AND(H2>=EDATE(A2,-1),COUNTIF($G$2:G2,G2),H2<=EOMONTH(EDATE(A2,-1),0)),1,0))

    Again, removing that COUNTIF gives same results so get rid of that too.

    =IF(SUMPRODUCT(($G$2:$G2=G2)*($A$2:$A2=$A2))>1, 0, IF(AND(H2>=EDATE(A2,-2),COUNTIF($G$2:G2,G2),H2<=EOMONTH(EDATE(A2,-2),0)),1,0))

    Does that help?

  7. #7
    Registered User
    Join Date
    04-29-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Count formula

    Hello ChemiseB,

    Thank you for your formulas-) I am sending once more my file. Would you please look at it? especially at "Sum" file. "P2" formula does not pick up properly in row 8, R8.
    Also, for some reason formulas do not work in rows 7,9,11,13,15... Possible- the reason in formatting in rows 4 and 5?

    I would appreciate if you could fix the formulas-)

    Thank you.
    Attached Files Attached Files

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

    Re: Count formula

    Okay, working one formula at a time. In E7,

    =IFERROR((COUNTIFS(O_D!$A:$A,$E$5,O_D!$H:$H,">="&E5,O_D!$H:$H,"<="&E4))/E6,"")

    There are no cells where A is january and H is also January. What are you looking for?

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

    Re: Count formula

    In E8, there is only a sum of 1 P2 in January. What are you expecting there and why?

  10. #10
    Registered User
    Join Date
    04-29-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Count formula

    Yes, you are right regarding E7. Thank you.
    E8 picks up numbers from sheet O_D Column "O". cells 12 and 16 have 1= 2. E8 shows 1.

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

    Re: Count formula

    Ahh, I believe the formula you want in row 8 is

    =SUMIFS(tbData[[P2 ]],tbData[gfap],IF($I$2="All","*",$I$2),tbData[Location],$B$2,tbData[Unique patients],1,tbData[ymd_last_service],">="&E$5,tbData[ymd_last_service],"<"&EDATE(E$5,1))
    You were looking at column "DATE" instead of "ymd_last_service"

  12. #12
    Registered User
    Join Date
    04-29-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Count formula

    Sorry.. we do not have to pay attention to "ymd_last_service". We care about Date Columns A and H.

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

    Re: Count formula

    Okay, so with this formula, I believe you are not looking for "Date" which is column A but "ymd_first_service" which is column H.

    =SUMIFS(tbData[[P2 ]],tbData[gfap],IF($I$2="All","*",$I$2),tbData[Location],$B$2,tbData[Unique patients],1,tbData[ymd_first_service],">="&E$5,tbData[ymd_first_service],"<"&EDATE(E$5,1))

  14. #14
    Registered User
    Join Date
    04-29-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Count formula

    When I put in G8 this formula: .=SUMIFS(tbData[[P2 ]],tbData[gfap],IF($I$2="All","*",$I$2),tbData[Location],$B$2,tbData[Unique patients],1,tbData[ymd_first_service],">="&G$5,tbData[ymd_first_service],"<"&EDATE(G$5,1))
    It give me "1" instead of "2".

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

    Re: Count formula

    Okay, we can go back to using "Date" (Col A) which will give you the correct value for Col G

    Are you looking to SUM IF either A or H is within that month?

  16. #16
    Registered User
    Join Date
    04-29-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Count formula

    It is better H. Please try test yourself first to match numbers in Sum from O_D. Thank you

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

    Re: Count formula

    Okay, switching back to Date In C8 copied (copy and paste) to D8:P8

    =SUMIFS(tbData[[P2 ]],tbData[gfap],IF($I$2="All","*",$I$2),tbData[Location],$B$2,tbData[Unique patients],1,tbData[ymd_first_service],">="&G$5,tbData[ymd_first_service],"<"&EDATE(G$5,1))

    This seems to be counting correctly.
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    04-29-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Count formula

    No...Unfortunately.. pls look at cell F8- it shows "1", but should be "2", if you look at column "O" in sheet O_D in cell O12 and O16 there are 1 and 1, so it should be 2 in F8..

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

    Re: Count formula

    For F8, must be a unique patient, only 1 of 2 "1's" in P2 (Col O) is a unique patient. Remove that criteria to get 2

  20. #20
    Registered User
    Join Date
    04-29-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Count formula

    Ok. Thank you.

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

    Re: Count formula

    Glad to help

+ 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 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
  2. Formula to count days and reset count
    By daviddelatorre in forum Excel General
    Replies: 8
    Last Post: 05-27-2015, 09:25 AM
  3. [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
  4. [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
  5. [SOLVED] text count issue, it seems to count the formula also?
    By randypang in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-28-2013, 03:27 AM
  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