+ Reply to Thread
Results 1 to 15 of 15

Counting occurrences not values.. Counting blocks of words in columns

  1. #1
    Registered User
    Join Date
    03-27-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Counting occurrences not values.. Counting blocks of words in columns

    Hi,

    Hope you can help, I've been looking for a solution for a while.

    So I've got a rota:

    I have a string of dates in columns, row 1 & under those will be shifts and/or a code to indicate what that user is doing that day i.e. "Sick".

    I need a formula that can be tacked onto the end of the rota in each row for 400+ rows (once per user so it cannot be too heavy) that displays the occurrences of these codes.

    By occurrences I mean blocks of sickness, if the user was sick once in week 1 & then 3 days sick in week 2 that'll be 2 occurrences but 4 days sickness.

    Example:

    01/02/2016 Sick
    02/02/2016 0700-1530
    03/02/2016 0700-1530
    04/02/2016 Sick
    05/02/2016 Sick
    06/02/2016 Sick
    07/02/2016 0700-1530
    08/02/2016 0700-1530
    09/02/2016 0700-1530
    10/02/2016 Sick

    This user has 3 occurrences of being off sick, however they've had 5 sick days.

    Thanks

  2. #2
    Valued Forum Contributor
    Join Date
    05-14-2012
    Location
    Unknown
    MS-Off Ver
    Unseen
    Posts
    429

    Re: Counting occurrences not values.. Counting blocks of words in columns

    Ah, the old Bradford Factor. Suggest you post a sample workbook with some typical examples.

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

    Re: Counting occurrences not values.. Counting blocks of words in columns

    Try this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Confirmed with ctrl+shift+enter (not just enter)

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

    Re: Counting occurrences not values.. Counting blocks of words in columns

    Try this...

    Data Range
    A
    B
    C
    D
    1
    Date
    Shift
    ------
    Occurrences
    2
    1/2/2016
    Sick
    3
    3
    2/2/2016
    0700-1530
    4
    3/2/2016
    0700-1530
    5
    4/2/2016
    Sick
    6
    5/2/2016
    Sick
    7
    6/2/2016
    Sick
    8
    7/2/2016
    0700-1530
    9
    8/2/2016
    0700-1530
    10
    9/2/2016
    0700-1530
    11
    10/2/2016
    Sick


    This array formula** entered in D2:

    =SUM(IF(FREQUENCY(IF(B2:B11="Sick",ROW(B2:B11)),IF(B2:B11<>"Sick",ROW(B2:B11)))>0,1))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  5. #5
    Registered User
    Join Date
    03-27-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Counting occurrences not values.. Counting blocks of words in columns

    Thanks for the replies so far. Not quite there yet. Attempting to upload an example document with your formula suggestions attempted so far.
    Attached Files Attached Files

  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: Counting occurrences not values.. Counting blocks of words in columns

    Just need to replace the ROW function with the COLUMN function:

    =SUM(IF(FREQUENCY(IF(B2:Q2="(SICK FULL)",COLUMN(B2:Q2)),IF(B2:Q2<>"(SICK FULL)",COLUMN(B2:Q2)))>0,1))

    Still array entered.

  7. #7
    Registered User
    Join Date
    03-27-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Counting occurrences not values.. Counting blocks of words in columns

    Ah perfect. Superstar! I should've spotted that. Thank you i'll continue testing & work on the rest. Removing gaps where it's a weekend is the next challenge sick Friday & then Sick Monday should count as one occurrence.

  8. #8
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,192

    Re: Counting occurrences not values.. Counting blocks of words in columns

    In Tony's formula change ROW to COLUMN as your data is across COLUMNS not down ROWS

    =SUM(IF(FREQUENCY(IF(B2:Q2="(SICK FULL)",COLUMN(B2:Q2)),IF(B2:Q2<>"(SICK FULL)",COLUMN(B2:Q2)))>0,1))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

  9. #9
    Registered User
    Join Date
    03-27-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Counting occurrences not values.. Counting blocks of words in columns

    Hi,

    I've sorted the weekend issue - however is there a way to include multiple code values within the formula? For example variations of "(SICK FULL)" where someone has entered the text incorrectly or in a different way. I.e. "SICK" / "(SICK HALF)" etc. ?

    Or a way I can implement a wildcard on the word Sick?

  10. #10
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,192

    Re: Counting occurrences not values.. Counting blocks of words in columns

    Try

    =SUM(IF(FREQUENCY(IF(ISNUMBER(SEARCH("*SICK*",B2:Q2)),COLUMN(B2:Q2)),IF(NOT(ISNUMBER(SEARCH("*SICK*",B2:Q2))),COLUMN(B2:Q2)))>0,1))

    Enter with Ctrl+Shift+Enter

  11. #11
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,192

    Re: Counting occurrences not values.. Counting blocks of words in columns

    Try

    =SUM(IF(FREQUENCY(IF(ISNUMBER(SEARCH("*SICK*",B2:Q2)),COLUMN(B2:Q2)),IF(NOT(ISNUMBER(SEARCH("*SICK*",B2:Q2))),COLUMN(B2:Q2)))>0,1))

    Enter with Ctrl+Shift+Enter

  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: Counting occurrences not values.. Counting blocks of words in columns

    Replace these strings...

    Replace:

    B2:Q2="(SICK FULL)"

    Replace with:

    ISNUMBER(SEARCH("Sick",B2:Q2))

    Replace:

    B2:Q2<>"(SICK FULL)"

    Replace with:

    ISERROR(SEARCH("Sick",B2:Q2))

  13. #13
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Counting occurrences not values.. Counting blocks of words in columns

    this seems simpler

    =SUMPRODUCT(IF(B2:Q2="(SICK FULL)",1,0),IF(B2:Q2<>C2:R2,1,0))
    as an array formula
    Happy with my advice? Click on the * reputation button below

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

    Re: Counting occurrences not values.. Counting blocks of words in columns

    Even simpler and does not need CSE...

    =SUMPRODUCT(--(B2:Q2="(SICK FULL)"),--(B2:Q2<>C2:R2))

    This version is even slightly faster to calculate than all the other versions.

    As long as there is no problem in referencing the R2 cell (not part of the data range, may contain other data) then this technique has great potential!

    Nice discovery!

  15. #15
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Counting occurrences not values.. Counting blocks of words in columns

    Quote Originally Posted by Tony Valko View Post
    Even simpler and does not need CSE...

    =SUMPRODUCT(--(B2:Q2="(SICK FULL)"),--(B2:Q2<>C2:R2))

    This version is even slightly faster to calculate than all the other versions.

    As long as there is no problem in referencing the R2 cell (not part of the data range, may contain other data) then this technique has great potential!

    Nice discovery!
    Yeah I need to use that form of sumproduct more often. I tend to stick with what I know rather than using this format.

+ 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. Counting blocks and continuing
    By kris18 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-29-2015, 11:39 AM
  2. Counting number of occurrences of phrase and sorting by two columns
    By edoctat in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-19-2013, 02:10 PM
  3. [SOLVED] Counting Occurrences of Items in a List Based on Separate List Values
    By wheel1 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-10-2013, 01:04 PM
  4. Replies: 1
    Last Post: 05-07-2013, 04:16 AM
  5. [SOLVED] Counting Blocks of Numbers
    By Omega71 in forum Excel General
    Replies: 2
    Last Post: 09-30-2012, 09:05 AM
  6. Counting Occurrences of Data in Multiple Columns
    By jgray in forum Excel General
    Replies: 3
    Last Post: 12-13-2010, 03:44 PM
  7. Counting Rows Then Counting Values in Columns
    By Michael via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2005, 12:05 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