+ Reply to Thread
Results 1 to 19 of 19

Count Number of Rows Based on Criteria

  1. #1
    Registered User
    Join Date
    07-04-2022
    Location
    Helsinki, Finland
    MS-Off Ver
    MS365 (PC) Version 2304
    Posts
    49

    Count Number of Rows Based on Criteria

    Hi!


    Sample workbook is attached. The headers are just default; the real dataset has unique headers.


    I have a table, which is 15 rows by 32 columns.


    I need to count the number of rows which contain a cell that is: empty OR contains the word "Unknown"

    but only if such a cell is in: Column 5 OR Column 6 OR Column 7 OR Column 8 OR Column 19 OR Column 21 OR Column 22 OR Column 31

    and only if the cell in Column 2 is: not empty.


    The word "Unknown" can only exist in the given columns {5, 6, 7, 8, 19, 21, 22, 31}, and not in any of the other columns.

    However, the word "Unknown" exists by default in every cell in all given columns, until it is supposed to be manually changed to a piece of data.


    For each row, the data entry starts in Column 2, so Column 2 should always have data in its respective row.

    So in the cases where, for example, B17 is empty and "Unknown" appears somewhere else in the row, that row should be excluded from the COUNT calculation.

    As soon as B17 is not empty, that row is included in the COUNT calculation, and it is then determined if it meets the criteria to be counted or not.


    In terms of empty cells ... they can appear anywhere in the table (people not entering the data, accidentally deleting data, etc).

    Row A10:AF10 has an empty D10, but it should not be counted because none of the given columns {5, 6, 7, 8, 19, 21, 22, 31} are empty, nor do they contain the word "Unknown".


    The expected result is: 14.


    Any help is appreciated; thanks in advance!
    Last edited by Nevanox; 05-24-2023 at 02:16 PM. Reason: Clarification.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,460

    Re: Count Number of Rows Based on Criteria

    In the real dataset, is there something in those column headings that can be used as an identifier? A common word? I suspect that your sample data is a little bit over-simplified.

    What is your expected result value?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    07-04-2022
    Location
    Helsinki, Finland
    MS-Off Ver
    MS365 (PC) Version 2304
    Posts
    49

    Re: Count Number of Rows Based on Criteria

    The column headings in the real dataset are all quite unique; there are no commonalities between them.


    In the case of my sample workbook, the expected result is:

    14


    All rows in the table have either an empty cell or contain the word "unknown" in one or more of the aforementioned specific columns, except for A10:AF10.
    Last edited by Nevanox; 05-24-2023 at 11:34 AM. Reason: Clarification.

  4. #4
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Count Number of Rows Based on Criteria

    like this?
    with Power Query
    CountRows
    14

    Please Login or Register  to view this content.
    Last edited by sandy666; 05-24-2023 at 01:53 PM. Reason: update

  5. #5
    Registered User
    Join Date
    07-04-2022
    Location
    Helsinki, Finland
    MS-Off Ver
    MS365 (PC) Version 2304
    Posts
    49

    Re: Count Number of Rows Based on Criteria

    Hi Sandy!


    Thanks for your message.

    I would prefer a solution that uses normal Excel formulas; not Power Query or Pivot Tables.


    I appreciate it anyway, though!

  6. #6
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,410

    Re: Count Number of Rows Based on Criteria

    In your sample workbook empty cells and cells with "Unknown" only exists in the given columns and never exists in other columns.

    If that's always the case, please try
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Count Number of Rows Based on Criteria

    Quote Originally Posted by Nevanox View Post
    I would prefer a solution that uses normal Excel formulas; not Power Query or Pivot Tables
    No problem
    Have a nice day

  8. #8
    Registered User
    Join Date
    07-04-2022
    Location
    Helsinki, Finland
    MS-Off Ver
    MS365 (PC) Version 2304
    Posts
    49

    Re: Count Number of Rows Based on Criteria

    Hi HansDouwe,


    Thanks again for posting a solution to another one of my problems!

    You bring up a good point ...


    My apologies for not realising earlier that there are potential scenarios that I didn't think about.

    I've attached another workbook to demonstrate the additional possibilities.


    The word "unknown" can only exist in the given columns {5, 6, 7, 8, 19, 21, 22, 31}, and not in any of the other columns.

    However, the word "unknown" exists by default in every cell in all given columns, until it is supposed to be manually changed to a piece of data.


    For each row, the data entry starts in Column2, so Column2 should always have data.

    So in the cases where, for example, B17 is empty and "unknown" appears somewhere else in the row, that row should be excluded from the COUNT calculation.

    As soon as B17 is not empty, that row is included in the COUNT calculation, and it is then determined if it meets the criteria to be counted or not.


    In terms of empty cells ... they can appear anywhere in the table (people not entering the data, accidentally deleting data, etc).

    Row A10:AF10 now has an empty D10, but it should not be counted because none of the given columns {5, 6, 7, 8, 19, 21, 22, 31} are empty, nor do they contain the word "unknown".


    The expected result for this workbook is still: 14.


    My sincere apologies again for wasting your time with a problem that I did not think about thoroughly.

    I hope it is now more clear!

  9. #9
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,410

    Re: Count Number of Rows Based on Criteria

    In this case it is not so easy to adjust the formula of post #6, I'll try adjust the formula tomorrow. Its a nice case.

  10. #10
    Registered User
    Join Date
    07-04-2022
    Location
    Helsinki, Finland
    MS-Off Ver
    MS365 (PC) Version 2304
    Posts
    49

    Re: Count Number of Rows Based on Criteria

    I really appreciate you (and everyone else) taking a look at it!

    Take care

  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 Number of Rows Based on Criteria

    Please try

    =SUM(--BYROW(FILTER(Table1,ISNUMBER(XMATCH(Table1[#Headers],"column"&TEXTSPLIT("5, 6, 7, 8, 19, 21, 22, 31",", ")))),LAMBDA(a,OR(ISNUMBER(SEARCH("Unknown",a)),a=0))))

  12. #12
    Registered User
    Join Date
    07-04-2022
    Location
    Helsinki, Finland
    MS-Off Ver
    MS365 (PC) Version 2304
    Posts
    49

    Re: Count Number of Rows Based on Criteria

    Hey Bo_Ry,

    Thanks for your message!


    Unfortunately, your solution is returning 21, when it should return 14.

    Also, I can't rely on matching the headers, as the headers in the real dataset are all unique.


    I appreciate your help, though!

  13. #13
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,410

    Re: Count Number of Rows Based on Criteria

    I think Bo_Ry's 21 is perfect, because you added 7 new rows to the table that are also counted.

  14. #14
    Forum Contributor John Vergara's Avatar
    Join Date
    01-17-2022
    Location
    Colombia
    MS-Off Ver
    365
    Posts
    200

    Re: Count Number of Rows Based on Criteria

    Hi to all!

    One option could be:
    PHP Code: 
    =SUM(BYROW(CHOOSECOLS(Table1,5,6,7,8,19,21,22,31),LAMBDA(x,N(SUM((x="")+(ISNUMBER(FIND("Unknown",x))))>0)))) 
    And yes... the result is 21. Blessings!
    A out-of-context text is a pretext.
    Consider adding reputation points to all the people who help you with your question/problem.

  15. #15
    Registered User
    Join Date
    07-04-2022
    Location
    Helsinki, Finland
    MS-Off Ver
    MS365 (PC) Version 2304
    Posts
    49

    Re: Count Number of Rows Based on Criteria

    But the result should not be 21 ... the result should be 14.

    Those 7 new rows should not be counted because the cell in Column 2 for each row is empty.

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,460

    Re: Count Number of Rows Based on Criteria

    Try this:

    =SUM(BYROW(CHOOSECOLS(FILTER(Table1,Table1[Column2]<>""),5,6,7,8,19,21,22,31),LAMBDA(x,N(SUM((x="")+(ISNUMBER(FIND("Unknown",x))))>0))))

  17. #17
    Registered User
    Join Date
    07-04-2022
    Location
    Helsinki, Finland
    MS-Off Ver
    MS365 (PC) Version 2304
    Posts
    49

    Re: Count Number of Rows Based on Criteria

    AliGW, that works perfectly, thank you.

    And thank you to everyone else as well.

    Sorry that this wasn't such a clear case ... I was confusing myself at times, but it's working now

  18. #18
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,460

    Re: Count Number of Rows Based on Criteria

    Glad to have helped.

    If you have not already done so, you may not be aware that you can thank anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of all those who offered help.

  19. #19
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,410

    Re: Count Number of Rows Based on Criteria

    Thanks for the feedback and rep .

+ 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: 1
    Last Post: 02-25-2021, 01:04 PM
  2. [SOLVED] Count number of lines based on text and number criteria, without duplicates
    By HVCompleto in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-28-2017, 07:17 AM
  3. Replies: 4
    Last Post: 11-01-2016, 03:28 PM
  4. [SOLVED] Count number of occurrences based on criteria in multiple columns and rows
    By gerryger in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-22-2015, 08:13 PM
  5. [SOLVED] Count number of rows meeting either criteria
    By abousetta in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 11-14-2014, 05:35 AM
  6. Trying to count number of rows where criteria are met in columns
    By kfloyd in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-10-2013, 01:45 PM
  7. Count number of rows with multiple criteria
    By spinx in forum Excel General
    Replies: 5
    Last Post: 09-17-2010, 09:17 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