+ Reply to Thread
Results 1 to 24 of 24

Counting how often numbers in a range occur in rows of data

  1. #1
    Registered User
    Join Date
    08-14-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    8

    Counting how often numbers in a range occur in rows of data

    I have rows and rows of numbers and I'd like excel to count how many times numbers occur in the 40s, 30s, 20s and 10s

    Example:
    Row 1: 10 11 32 38 41 44
    Row 2: 12 17 23 31 43 46
    Row 3: 15 18 23 29 32 43

    For the 40s:
    The number of times a number occurs twice in the 40s is 2

    the number of times a number occurs once in the 40s is 1

    the number of times a number appears three times in the 40s is 0


    For the 30s:
    The number of times a 30s number appears once is 2

    The number of times a 30s number appears twice is 1,

    The number of times a number in the 30s appears three times or not at all in a row is 0


    so as i have 6 columns of numbers, i'd like it to calculate how often numbers in the 40s, 30s, 20s, and 10s appear once, twice, three times, four times, five times, and six times in each row
    Does anyone have any idea what formula I could use? Any help would really be appreciated.

  2. #2
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Counting how often numbers in a range occur in rows of data

    the number of times a number occurs once in the 40s is 1
    ... 2?
    appear once, twice, three times, four times, five times, and six times
    and 0 times?
    in each row
    Really? Your figures indicate you are considering all rows at once.
    CC


    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

  3. #3
    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: Counting how often numbers in a range occur in rows of data

    You might be able to work with variations of this
    Please Login or Register  to view this content.

    See the attached workbook

    Hope this helps
    Attached Files Attached Files
    Last edited by Marcol; 08-14-2010 at 08:30 PM. Reason: Oops! mixed up my $s
    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.

  4. #4
    Registered User
    Join Date
    08-14-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Counting how often numbers in a range occur in rows of data

    Yes, I'd like excel to count in all the rows how often numbers in the 40s, 30s, 20s, etc occur once, twice, three, four, five and six times per row and then total them and produce a summary table with the once, twice, three times totals.

    So in the example:

    Row 1: 10 11 32 38 41 44
    Row 2: 12 17 23 31 43 46
    Row 3: 15 18 23 29 32 43

    The number of times a number in the 40s only occurs once in all rows displayed is 1 (Row 3)

    The number of times a number in the 40s occurs twice in all the rows is 2 (once in Row 1 and once in Row 2)

    The number of times numbers in the 40s occurs three, four, five, or six times (so far) is 0.

    I could manually count them and produce a table like so:

    0x 1x 2x 3x 4x 5x 6x
    40s 0 1 2 0 0 0 0
    30s 0 2 1 0 0 0 0
    20s 1 1 1 0 0 0 0
    10s 0 0 3 0 0 0 0
    0s 0 0 0 0 0 0 0


    The problem is there are over 1000 rows and it's a growing list. What formula or formulas would I need to employ to get Excel to produce such a summary table.

    Thanks.

  5. #5
    Registered User
    Join Date
    08-14-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Counting how often numbers in a range occur in rows of data

    Thank you Marcol. I will take a look at that sheet you provided

  6. #6
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Counting how often numbers in a range occur in rows of data

    I *think* Marcol, that the OP needs something more substantive - a count of the counts of each of the numbers in each interval.

    i.e. 40, 41, 41, 42, 45, 47, 47, 47, 49
    40 occurs once
    41 occurs twice
    ...
    49 occurs once

    *leads to*

    (four numbers occur zero times) - not sure if the OP needs this (as queried above)
    four numbers occur once
    one number occurs twice
    1 number occurs three times

    Which seems quite fun... something involving arrays, probably referencing row numbers according to my taste.

  7. #7
    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: Counting how often numbers in a range occur in rows of data

    Possibly, but I read
    in the 40s
    to be 40 to 49

    Maybe not...

  8. #8
    Registered User
    Join Date
    08-14-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Counting how often numbers in a range occur in rows of data

    That's right. Sorry I should have given a better range. 40s means how often numbers from 40 to 49 occur in all the rows. 30s is 30 to 39, etc.

  9. #9
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Counting how often numbers in a range occur in rows of data

    With this list in A1:F15
    Please Login or Register  to view this content.
    And these column headings in H1:K1
    blank 1 2 3

    And these row headings in H2:H5
    40
    30
    20
    10

    This ARRAY FORMULA, committed with CTRL+SHIFT+ENTER (instead of just ENTER)
    begins the "count" calculations.
    Please Login or Register  to view this content.
    Copy I2 and paste into J2:K2
    Copy I2 and paste into I3:K5

    With the above data, the results look like this:
    Please Login or Register  to view this content.
    Is that something you can work with?
    Attached Files Attached Files
    Last edited by Ron Coderre; 08-14-2010 at 08:44 PM.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  10. #10
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Counting how often numbers in a range occur in rows of data

    Difference between:
    calculate how often numbers in the 40s, 30s, 20s
    and
    calculate how often each number in the 40s, 30s, 20s

    but I'd like you to clarify the questions I've asked to avoid going off half-cocked

  11. #11
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Counting how often numbers in a range occur in rows of data

    Based on the first example, I believe we are being asked to count
    the number of times a number in the 40's occurs in the same row
    a certain number of times.

    In this example:
    Please Login or Register  to view this content.
    In the above:
    1 row contains 1 40
    2 rows contain 2 40's
    1 row contains 3 40's

    (I hope I'm right, because my whole response was based on the above)

  12. #12
    Registered User
    Join Date
    08-14-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Counting how often numbers in a range occur in rows of data

    Yes, Ron has provided the exact solution I'm looking for and in an amazingly short time. I'm going to look at it now and see if I can understand how it works. I love learning new formulas and functions I never knew existed

    In the formula, say in I2:

    {=SUM(--(FREQUENCY(IF((INT($A$1:$F$15/10)*10=$H2),ROW($A$1:$F$15)),ROW($A$1:$A$16)-1)=I$1))}
    Could you explain why reference $A$1:$F$15 is divided by 10 (hopefully highlighted in bold in the quote above)?


    Many thanks guys.

  13. #13
    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: Counting how often numbers in a range occur in rows of data

    Hmmm...?

    It's not really a big deal to count the occurences based on my original suggestion.

    I agree, however, that a single step is probably better.

    See the attached
    Attached Files Attached Files

  14. #14
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Counting how often numbers in a range occur in rows of data

    Quote Originally Posted by geekalpha View Post
    ...Could you explain why reference $A$1:$F$15 is divided by 10 (hopefully highlighted in bold in the quote above)?
    Each of the values is first divided by 10 then converted to an integer. the result is the digit in the 10's column...but in the digit's slot.
    Example:
    41 becomes 4
    38 becomes 3

    So, I multiplied by 10 so we could compare the resulting value to your test values: 10, 20, 30, 40

    I hope that helps.

  15. #15
    Registered User
    Join Date
    08-14-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Counting how often numbers in a range occur in rows of data

    In other words, Ron: genius! I would never have even thought that way let alone been able to actually formulate it. So a huge thank you.

    I've tried to extend it to also count how often no numbers, say, from 20 to 29 occur in the rows. So some rows read:

    Row 1: 10 11 32 38 41 44 (contains no integer from 20 to 29)
    Row 4: 10 11 32 38 41 44 (also contains no integer from 20 to 29)

    and none of the rows contain any numbers from 1 to 9, i.e. 15 rows contain no numbers from 1 to 9.

    If the results of these "absences" were in column L (L1 = 0), they should total up as follows:

    ___L
    ___0
    40 0
    30 0
    20 5
    10 0
    0 15


    If I change the end of the formula to L$1 where L1 = 0, in the rows of data you provided, it counts the "absences" as:

    40 2
    30 2
    20 7
    10 2
    0 17 !

    Using the formula:

    =SUM(--(FREQUENCY(IF((INT($A$1:$F$15/10)*10=$H6),ROW($A$1:$F$15)),ROW($A$1:$A$16)-1)=L$1))

    How do I then adjust the formula because now I'm asking excel to count the absence of a range in each of the rows?

    Is it possible?

    Many thanks.

  16. #16
    Registered User
    Join Date
    08-14-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Counting how often numbers in a range occur in rows of data

    Thanks Marcol for the alternative version. Having two routes means I can use one route to check on the other, so it's very much appreciated

  17. #17
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Counting how often numbers in a range occur in rows of data

    I think I'd use this approach to count the absence of values in the range:
    H6: 0 <-for values between 0 and 9
    L1: 0

    ARRAY FORMULA
    Please Login or Register  to view this content.
    Copy L2 and paste into L3:L5

    With the sample data these values are returned
    L2: 0 <-rows containing no 40's
    L3: 0 <-rows containing no 30's
    L4: 5 <-rows containing no 20's
    L5: 0 <-rows containing no 10's
    L6: 15 <-rows containing no digits

    Does that help?

  18. #18
    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: Counting how often numbers in a range occur in rows of data

    Hi Ron Coderre

    I've been fighting all day with this thread to try to understand it better!

    I think geekalpha might be looking for 1>9 instead of 0>9 and then just 0

    The 0 bit is no problem
    Please Login or Register  to view this content.
    It's the 1>9 that has me beaten.

    (This might also apply to the formula you just posted.)

    I can get to result easily with my rather basic method, but I would like to complete the set before posting a combined demo workbook.

    Would you mind helping out?

  19. #19
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Counting how often numbers in a range occur in rows of data

    If 1-9 which group does 20 (and 30, 40 etc.) belong in?

  20. #20
    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: Counting how often numbers in a range occur in rows of data

    These groups would remain unchanged 10>19, 20> 29,....etc.

    It's how to remove the counts of zeros from 0>9 I'm having problems with.
    Last edited by Marcol; 08-15-2010 at 02:35 PM.

  21. #21
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Counting how often numbers in a range occur in rows of data

    Why don't you do exactly that? Sum 0-9 then subtract 0 to leave 1-9...

  22. #22
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Counting how often numbers in a range occur in rows of data

    If you want to ignore 0's in the data, try this...

    Using the example I posted previously,
    this array formula would go in cell
    Please Login or Register  to view this content.
    Copy I2 and paste into J2:K2
    Copy I2 and paste into J3:K3

    and...(array formula)
    Please Login or Register  to view this content.
    Copy L2 and paste into L3:L6

    Does that help?

  23. #23
    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: Counting how often numbers in a range occur in rows of data

    Spot on Ron

    I've taken the liberty of comparing my rather primitive method to yours in the attached workbook.

    All credit to you.

    I hope it helps geekalpha as much as it has helped me.

    Thanks again.
    Attached Files Attached Files

  24. #24
    Registered User
    Join Date
    08-14-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Counting how often numbers in a range occur in rows of data

    Thank you everyone for the great support.

    Marcol is right that I want to count occurences and absences of numbers in the following groups:

    1 - 9
    10 - 19
    20 - 29
    30 - 39
    40 - 49

    Sorry I didn't outline it like that but it's a growing operation so putting it into words wasn't easy. Ron Codorre seems to have provided the solutions so I'll take a look at the formulas and try to learn how they work, and let you know how I get on.

    Thanks again

+ 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