+ Reply to Thread
Results 1 to 18 of 18

Count number times same value is present in a single Row of a larger range.

  1. #1
    Registered User
    Join Date
    08-23-2015
    Location
    Australia
    MS-Off Ver
    MS Mac:2011
    Posts
    4

    Count number times same value is present in a single Row of a larger range.

    G'Day,

    I have been struggling with COUNTIFS, making a differnet countif/countifs for each row and adding them together but it just seems to count every time it sees each value, regardless if they are on the same line.


    The range is C20:L147. The 15 values will be used all through the range over and over again. I want to count each time two specific values are present on the same row.

    Thanks

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Count number times same value is present in a single Row of a larger range.

    Hi ManinOZ and welcome to the forum,

    This sounds like a job for the Frequency function. See the attached where I've done a problem similar to yours above. See if it works and if not then modify the question and/or supply a sample workbook.

    I used this formula and pulled down.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    08-06-2015
    Location
    India
    MS-Off Ver
    2010
    Posts
    23

    Re: Count number times same value is present in a single Row of a larger range.

    If you would like to count the number of time a value is repeated in big data bank, then you can get it for each cell value in next column.
    use this formula =countif(Range,criteria).
    Example- if you want to check the number of time a cell value have been repeated just in next cell of different column

    =countif($A$2:$A$1000,A2) (you will write this formula in B2- Then will come to know that the value in cell A2 is been repeated n number of time) just drag it to get the same result for each cells.

    If you need let me know I will forward you the sample sheet.

    If It solved your problem, then click on * BUTTON BELOW I.e- ADD REPUTATION

  4. #4
    Registered User
    Join Date
    08-23-2015
    Location
    Australia
    MS-Off Ver
    MS Mac:2011
    Posts
    4

    Re: Count number times same value is present in a single Row of a larger range.

    Thanks, for your replies, I think however my question was not clear.

    I have attached an example
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    07-30-2014
    Location
    USA
    MS-Off Ver
    Version 14.4.3, Mac 2011
    Posts
    145

    Re: Count number times same value is present in a single Row of a larger range.

    Mr. Khan said it right,
    But you only want to show a 1 (TRUE) if both 648 AND 642 are there, and a 0 (FALSE) if they BOTH are not there.

    =IF( AND(COUNTIF(C22:K22, 648)>0,COUNTIF(C22:K22, 642)>0), 1, 0)

    drag that down and then sum this new column
    Last edited by RedSummer; 08-24-2015 at 03:54 PM.

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count number times same value is present in a single Row of a larger range.

    I want to have the number of times both "648" and "642" appear in the same row
    Will there ever be duplicates on a row?

    648...648...642
    642...640...642
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  7. #7
    Forum Contributor
    Join Date
    07-30-2014
    Location
    USA
    MS-Off Ver
    Version 14.4.3, Mac 2011
    Posts
    145

    Re: Count number times same value is present in a single Row of a larger range.

    Quote Originally Posted by Tony Valko View Post
    Will there ever be duplicates on a row?

    648...648...642
    642...640...642
    I don't think that is relevant to his question in the example sheet
    "I want to have the number of times both "648" and "642" appear in the same row"

    Relooking at what he wanted I realize my formula should be >1, not >0

    Here you go:
    =IF( AND(COUNTIF(C22:K22, 648)>0,COUNTIF(C22:K22, 642)>1), 1, 0)

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count number times same value is present in a single Row of a larger range.

    Quote Originally Posted by RedSummer View Post
    I don't think that is relevant to his question in the example sheet
    At a quick glance I didn't see any dupes on any row.

    However, it is relevant to my proposed solution.

    Assuming there will not be dupes on any row:

    =SUMPRODUCT(--(MMULT(--ISNUMBER(MATCH(C20:K147,{642,648},0)),{1;1;1;1;1;1;1;1;1})=2))

    That counts the entire range.

  9. #9
    Forum Contributor
    Join Date
    07-30-2014
    Location
    USA
    MS-Off Ver
    Version 14.4.3, Mac 2011
    Posts
    145

    Re: Count number times same value is present in a single Row of a larger range.

    Oh apologies, Mr. Valko you are doing something way smarter and above my skills. Copying off of you,
    If there are dupes, wouldn't doing something silly like

    =SUMPRODUCT(--(MMULT(--ISNUMBER(MATCH(C20:K147,{642,648},0)),{1;1;1;1;1;1;1;1;1})=2)) + SUMPRODUCT(--(MMULT(--ISNUMBER(MATCH(C20:K147,{642,648,642},0)),{1;1;1;1;1;1;1;1;1})=3))

    do work?

  10. #10
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count number times same value is present in a single Row of a larger range.

    No, that won't work.

    Not sure how to account for dupes.

  11. #11
    Forum Contributor
    Join Date
    07-30-2014
    Location
    USA
    MS-Off Ver
    Version 14.4.3, Mac 2011
    Posts
    145

    Re: Count number times same value is present in a single Row of a larger range.

    Odd, I tested it and it seemed to work...

  12. #12
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count number times same value is present in a single Row of a larger range.

    With just this data in the range:

    C20 = 648
    D20 = 648

    Your formula returns 1. 642 is not present so the correct result should be 0.

  13. #13
    Forum Contributor
    Join Date
    07-30-2014
    Location
    USA
    MS-Off Ver
    Version 14.4.3, Mac 2011
    Posts
    145

    Re: Count number times same value is present in a single Row of a larger range.

    Thank you for explaining that to me. I totally overlooked that.

    So with that fix in,
    I realize that we need

    =IF( AND( IF(COUNTIF(C20:K20, 648)>0,TRUE,FALSE), IF(COUNTIF(C20:K20, 642)>0,TRUE,FALSE) ) , 1, 0)

    In a new column and to sum that. I'm still trying to teach myself if you can do something with matrices for this.
    Last edited by RedSummer; 08-24-2015 at 08:02 PM.

  14. #14
    Forum Contributor
    Join Date
    07-30-2014
    Location
    USA
    MS-Off Ver
    Version 14.4.3, Mac 2011
    Posts
    145

    Re: Count number times same value is present in a single Row of a larger range.

    OKAY

    I think this does the trick!! One formula, cross references that each row has a 648 in it with each row has a 642 in it. For each row where both a 648 and 642 are in it, should say true or something, i don't really know. It made sense when I messed with it. XD

    =SUMPRODUCT(--(MMULT(--ISNUMBER(MATCH(C20:K147,{648},0)),{1;1;1;1;1;1;1;1;1})=1),--(MMULT(--ISNUMBER(MATCH(C20:K147,{642},0)),{1;1;1;1;1;1;1;1;1})=1))

  15. #15
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count number times same value is present in a single Row of a larger range.

    Like this...

    =(COUNTIF(C20:K20, 648)>0)+(COUNTIF(C20:K20, 642)>0)

    Then, do a COUNTIF(Range,2)

  16. #16
    Registered User
    Join Date
    08-23-2015
    Location
    Australia
    MS-Off Ver
    MS Mac:2011
    Posts
    4

    Re: Count number times same value is present in a single Row of a larger range.

    There should no be any duplicates in the same row. sorry for the bad example data.

  17. #17
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count number times same value is present in a single Row of a larger range.

    Quote Originally Posted by ManinOZ View Post
    There should no be any duplicates in the same row. sorry for the bad example data.
    OK, then the formula in post #8 should do what you want.

  18. #18
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count number times same value is present in a single Row of a larger range.

    Just an FYI...

    This will account for dupes.

    Data Range
    A
    B
    C
    5
    1
    1
    1
    6
    1
    2
    3
    7
    2
    2
    3
    8
    2
    2
    1
    9
    ------
    ------
    ------


    Count the number of rows that contain both 1 and 2.

    =SUMPRODUCT(--(MMULT(--(A5:C8=1),{1;1;1})>0),--(MMULT(--(A5:C8=2),{1;1;1})>0))

+ 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: 10
    Last Post: 10-09-2014, 08:06 PM
  2. Row Count is 15 times larger than actual rows
    By DanaHoff in forum Excel General
    Replies: 5
    Last Post: 04-12-2014, 11:14 PM
  3. count the number of times a number appears in a specific range
    By myjebay1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-18-2013, 11:01 AM
  4. [SOLVED] Lookup and count number of times a number is present???
    By greenfox74 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 12-31-2012, 12:21 PM
  5. Count number of times value is present i area.
    By bendixboogie in forum Excel General
    Replies: 3
    Last Post: 07-06-2011, 01:10 AM
  6. Count how many times a number appears within a range of two numbers
    By Maristar in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-02-2009, 10:56 AM
  7. Replies: 3
    Last Post: 07-14-2005, 08:53 AM

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