+ Reply to Thread
Results 1 to 8 of 8

Formula to count how many numbers repeat in a column.

  1. #1
    Registered User
    Join Date
    07-12-2010
    Location
    Montreal
    MS-Off Ver
    Excel Mac v.X
    Posts
    7

    Formula to count how many numbers repeat in a column.

    My spreadsheet records admissions/discharges on a hospital floor. Each admission and its corresponding discharge are recorded in 1 row. The unique hospital card number of each patient is admitted in Column D (number can be anywhere from 4 to 8 digits).

    What formula will yield the number of hospital card numbers that are repeated in Column D (the number of patients who have been admitted more than once)?

    If Column D contains:
    4444
    4444
    7777777
    55555
    4444
    666666
    88888888
    7777777
    then the formula should yield "2" (because the 2 numbers "4444" and "7777777" are repeated).

    I think this is complicated enough for now. Eventually, though, I want to have cells that show how many patients have been admitted 2 times; how many have been admitted 3 times; etc. Hopefully I will be able to figure out those formulae on my own, referring to the cell I am asking about here.

    Thanks in advance for any suggestions/advice,

    - Simon
    Last edited by simonheller; 11-26-2010 at 09:08 PM. Reason: forgot to include example

  2. #2
    Registered User
    Join Date
    11-22-2010
    Location
    Finland
    MS-Off Ver
    Excel 2003, 2007
    Posts
    95

    Re: Formula to count how many numbers repeat in a column.

    Well here's a harsh solution with one accessory column used. Result in B3.

    Edit: The round seems to be pretty useless. Just recalled memories of some ancient problems with 1/3, 1/6 etc. values with endless line of decimals.
    Attached Files Attached Files
    Last edited by KiPA; 11-26-2010 at 10:27 PM. Reason: info
    An example file is never useless!

    Tried an example function of mine and got errors?
    - Had you found them, replace ; with , and , with .

  3. #3
    Registered User
    Join Date
    11-22-2010
    Location
    Finland
    MS-Off Ver
    Excel 2003, 2007
    Posts
    95

    Re: Formula to count how many numbers repeat in a column.

    This might also work with the how-many-times problem:

    2 times: =COUNTIF(F:F;1/2)/2
    3 times: =COUNTIF(F:F;1/3)/3
    4 times: =COUNTIF(F:F;1/4)/4

    etc...

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Formula to count how many numbers repeat in a column.

    Assuming your data is not sorted on column D and begins in row 2

    In a spare column in row2
    Please Login or Register  to view this content.
    Drag/ Fill down

    Then filter this column for the number of repeats you are interested in.

    If you can sort the data in column D
    Please Login or Register  to view this content.
    Hope this helps
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Formula to count how many numbers repeat in a column.

    In terms of single cell:

    Please Login or Register  to view this content.
    I would suggest however you use a Pivot for this.
    Set Patient Card Number as both Row Label and Data Field (set to Count) and then order the results accordingly
    (this will give you a listing of patients and associated frequency)

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,592

    Re: Formula to count how many numbers repeat in a column.

    This will also work but for exact range:

    =SUMPRODUCT(--(COUNTIF(D1:D8,D1:D8)>1),1/COUNTIF(D1:D8,D1:D8))

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Formula to count how many numbers repeat in a column.

    @zbor... that's a pretty calculation intensive approach

    technically you could shorten based on the fact that the 2 separate arrays represent both sides of the division:

    Please Login or Register  to view this content.
    @simonheller, in terms of suggestions thus far ranked in order of my own entirely subjective order of preference:

    1 - Pivot Table
    2 - Use Helpers thereby making all subsequent calculations trivial
    3 - Use Basic Array (ie Frequency)
    4 - Use SUMPRODUCT

  8. #8
    Registered User
    Join Date
    07-12-2010
    Location
    Montreal
    MS-Off Ver
    Excel Mac v.X
    Posts
    7

    Re: Formula to count how many numbers repeat in a column.

    Thanks Marcol!

    Your formula =IF(D2=D3,"",IF(COUNTIF(D:D,D2)=1,"",COUNTIF(D:D,D2))) worked beautifully.

    I created a new column and put that formula in row 2 of it, then filled down to all the other rows. A number now appears in the row in which the most recent admission is recorded (but not if it is only the patient's first admission). It can be sorted with no problem too!

    And thanks for figuring out that
    "The unique hospital card number of each patient is admitted in Column D",
    was really supposed to read
    "The unique hospital card number of each patient admitted is recorded in Column D".

    I also created one-off cells that tell how many people have been admitted twice, three times, etc.:
    =COUNTIF(C2:C800,2), =COUNTIF(C2:C800,3), etc.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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