+ Reply to Thread
Results 1 to 8 of 8

COUNTIF between two times

Hybrid View

  1. #1
    Registered User
    Join Date
    04-21-2017
    Location
    Peterborough, United Kingdom
    MS-Off Ver
    2010
    Posts
    18

    COUNTIF between two times

    Hi guys,

    Hope you can help with this one.

    I have a rota that has a big list of names in the rows and days of the week in the columns.

    Each cell then says what shift/hours they worked for that day. So for example 08:30 - 15:30.

    What I want to do is track how many staff we had in at half an hour intervals.

    SO an example output would look like:
    08:00 - 102
    08:30 - 122
    09:00 - 121
    09:30 - 125
    etc

    Where each time represents how many people were working at that particular time.

    So far I have tried splitting each person unto two additional columns using LEFT & RIGHT to get their start and stop time, then using a COUNTIFS and TIME function but I can't seem to get it working.

    I have attached a simple example of what the data looks like (1st tab) and what the results should look like (2nd tab).

    Is anyone able to help me?
    Attached Files Attached Files
    Last edited by doodlelurch; 12-06-2018 at 10:26 AM.

  2. #2
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: COUNTIF between two times

    Given that no shift starts till 8:30 how can you have 102 people who are working then?

    You have not defined what you count, for example 10:15 - 15:45 how may staff are working between 13:30 and 14:00 ?

  3. #3
    Registered User
    Join Date
    04-21-2017
    Location
    Peterborough, United Kingdom
    MS-Off Ver
    2010
    Posts
    18

    Re: COUNTIF between two times

    The sheet attached is purely an example of 20 made up people. The number I wrote above is just what I'd like the output to look like not real numbers.

    So each half an hour interval would just count if they were present or not. For example, 10:15 - 15:45, would be a yes to 10:00 and 15:30 (and all times between) but would not be counted for 10:00 and 16:00.

    Does this make sense?

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,306

    Re: COUNTIF between two times

    Does it make sense to give dummy data that is not correctly calculated? No. The dummy data in your workbook should show correct and manually calculated example results.

    Please don't quote whole posts, especially when you are responding to the one immediately preceding your own - it's just clutter. It's OK to quote if you are responding to a post out of sequence, but limit quoted content to a few relevant lines that makes clear to whom and what you are responding. Thanks!

    For normal conversational replies, try using the QUICK REPLY box below.
    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. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  5. #5
    Registered User
    Join Date
    04-21-2017
    Location
    Peterborough, United Kingdom
    MS-Off Ver
    2010
    Posts
    18

    Re: COUNTIF between two times

    Quote Originally Posted by AliGW View Post
    Does it make sense to give dummy data that is not correctly calculated? No. The dummy data in your workbook should show correct and manually calculated example results.
    The dummy data is correct and contains no calculations, I purely wanted to give an example of what an output could look like in the forum before anyone opened up the dummy data excel.

    Apologies if this was confusing. I have (hopefully!) updated the original post to make it clearer.

  6. #6
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,222

    Re: COUNTIF between two times

    Please try at B2 Press Ctrl+Shift+Enter and copy down

    =SUM(IFERROR((--SUBSTITUTE(LEFT(Rota!$B$2:$B$21,5),".",":")<=A2)*(--SUBSTITUTE(RIGHT(Rota!$B$2:$B$21,5),".",":")>A2),))

  7. #7
    Registered User
    Join Date
    04-21-2017
    Location
    Peterborough, United Kingdom
    MS-Off Ver
    2010
    Posts
    18

    Re: COUNTIF between two times

    Quote Originally Posted by Bo_Ry View Post
    Please try at B2 Press Ctrl+Shift+Enter and copy down

    =SUM(IFERROR((--SUBSTITUTE(LEFT(Rota!$B$2:$B$21,5),".",":")<=A2)*(--SUBSTITUTE(RIGHT(Rota!$B$2:$B$21,5),".",":")>A2),))
    Brilliant! Thanks a lot Bo_Ry, works perfectly!

    Are you able to explain how it works?

    Don't feel obliged but it's always good to learn more on excel and hopefully means I won't have to ask on forums again or may be able to help other people in the future.

  8. #8
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,222

    Re: COUNTIF between two times

    Eg B3 "08.30-14.30"

    =--SUBSTITUTE(LEFT(Rota!B3,5),".",":")

    =--SUBSTITUTE(LEFT("08.30-14.30",5),".",":") =--SUBSTITUTE("08.30",".",":") =--"08:30" is TIME 8:30

    For RIGHT right will get TIME 14:00

    If Time in column A is between LEFT and RIGHT will get 1, if not will get 0
    Iferror for the Data in Rota that doesn't have time will result 0


    =SUM(IFERROR((--SUBSTITUTE(LEFT(Rota!$B$2:$M$21,5),".",":")<=A2)*(--SUBSTITUTE(RIGHT(Rota!$B$2:$M$21,5),".",":")>A2),))

    Change from Post #5 from B to M to for all date

+ 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. [SOLVED] Organizing/Plotting Times? Countif??
    By pshearer in forum Excel General
    Replies: 3
    Last Post: 03-26-2014, 05:50 AM
  2. CountIf falls between times
    By adam2308 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 01-05-2014, 09:49 AM
  3. COUNTIF for times????
    By RiceKrispy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2012, 12:49 PM
  4. Countif on times
    By Benson-112 in forum Excel General
    Replies: 4
    Last Post: 08-24-2009, 10:16 AM
  5. Replies: 4
    Last Post: 04-19-2009, 06:13 PM
  6. Countif time is between two nominated times
    By hopeless in excel in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-20-2006, 06:40 PM
  7. [SOLVED] COUNTIF:count the number of times
    By swarfmaker in forum Excel General
    Replies: 6
    Last Post: 10-02-2005, 07:05 PM
  8. [SOLVED] Countif("between start/end times)
    By Ian Jones in forum Excel General
    Replies: 1
    Last Post: 01-06-2005, 04:04 PM

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