+ Reply to Thread
Results 1 to 9 of 9

Formula/method to sort by specific time period within date+time ranges in cell

  1. #1
    Registered User
    Join Date
    01-15-2013
    Location
    London, England
    MS-Off Ver
    Excel 2016
    Posts
    10

    Question Formula/method to sort by specific time period within date+time ranges in cell

    Hi smart people!

    So I have a list of all customer orders placed over the last year.

    My objective is ultimately to see how many orders are placed during our out-of-hours periods (so, any orders placed before 8:30am, after 5:30pm, and at weekends).

    My date/time column looks like this...

    Capture column.PNG

    So I need a way to somehow filter the out of hours periods in this column. Ideally, I would be able to see some sort of table/visual of orders placed during open hours vs closed hours. Or failing that, just a way to literally filter them out so I can make my own calculations.

    Can anyone please help me? Thanks in advance!

  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
    79,369

    Re: Formula/method to sort by specific time period within date+time ranges in cell

    Will you please attach a sample Excel workbook? We are not able to work with or manipulate a picture of one and nobody wants to have to recreate your data from scratch.

    1. Make sure that your sample data are REPRESENTATIVE of your real data. The use of unrepresentative data is very frustrating and can lead to long delays in reaching a solution.

    2. Make sure that your desired results are also shown (mock up the results manually).

    3. Make sure that all confidential data is removed or replaced with dummy data first (e.g. names, addresses, E-mails, etc.).

    4. Try to avoid using merged cells as they cause lots of problems.

    Unfortunately the attachment icon doesn't work at the moment, so to attach an Excel file you have to do the following: just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.

    Please pay particular attention to point 2 (above): without an idea of your intended outcomes, it is often very difficult to offer appropriate advice.
    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
    01-15-2013
    Location
    London, England
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Formula/method to sort by specific time period within date+time ranges in cell

    Hi Ali,

    Thanks for this. I've stripped everything right back, removed anything confidential etc.

    So column A shows all my dates/times. I've shortened it to just the last 2 months to keep things simple...

    For mockups:
    Columns F, G, H, show the first set of results I need (by day)
    Columns L,M,N, show the second set of result I need (by month)

    (I am open to other methods/logic is easier/better, but this is essentially the information I need. I just can't figure out how to sort the data in column A based on specific times of the day/weekends etc.)

    I hope this makes sense! Thanks for your help :-)
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    01-15-2013
    Location
    London, England
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Formula/method to sort by specific time period within date+time ranges in cell

    Hi again all - If what I'm asking for is not possible, please say. Maybe I'm on a wild goose chase with this and it cannot be done?

  5. #5
    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
    79,369

    Re: Formula/method to sort by specific time period within date+time ranges in cell

    It's possible! However, it would be MUCH easier if your date column were split in two - one for the date and one for the time of the order. Is this feasible?

  6. #6
    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
    79,369

    Re: Formula/method to sort by specific time period within date+time ranges in cell

    So, just as an example, use Text to Columns to split the dates and times using the space as the delimiter, then it is as simple as this in G2 copied down:

    =IF(WEEKDAY(F2,2)<6,COUNTIFS($A$2:$A$1090,F2,$B$2:$B$1090,"<08:30")+COUNTIFS($A$2:$A$1090,F2,$B$2:$B$1090,">17:30"),COUNTIF($A$2:$A$1090,F2))

    and in H2 copied down:

    =IF(WEEKDAY(F2,2)<6,COUNTIF($A$2:$A$1090,F2)-G2,"N/A "&IF(WEEKDAY(F2,2)=6,"(Saturday)","(Sunday)"))
    Attached Files Attached Files
    Last edited by AliGW; 02-13-2018 at 07:10 AM.

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,604

    Re: Formula/method to sort by specific time period within date+time ranges in cell

    If you are stuck with using dates and times combined (or don't want to split them), then you can use this formula in cell G2:

    =IF(WEEKDAY(F2,2) < 6,SUMPRODUCT((INT($A$2:$A$1090)=F2)*((MOD($A$2:$A$1090,1) < TIME(8,30,0))+(MOD($A$2:$A$1090,1) > TIME(17,30,0)))),SUMPRODUCT(--(INT($A$2:$A$1090)=F2)))

    and this one in H2:

    =IF(WEEKDAY(F2,2) < 6,SUMPRODUCT((INT($A$2:$A$1090)=F2)*((MOD($A$2:$A$1090,1) > TIME(8,30,0))*(MOD($A$2:$A$1090,1) < TIME(17,30,0)))),"n/a")

    then copy down as required.

    Hope this helps.

    Pete

  8. #8
    Registered User
    Join Date
    01-15-2013
    Location
    London, England
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Formula/method to sort by specific time period within date+time ranges in cell

    Amazing, thanks both.
    I'll use Pete's one for the convenience of not splitting the dates and times.

    This is exactly what I needed. Thanks very much! (now to try and study the formula you've given me and figure out how it works for my own learning!)

    Thanks again!

  9. #9
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,604

    Re: Formula/method to sort by specific time period within date+time ranges in cell

    Once you have completed some more of the daily table, you can think about producing the monthly summaries from that table. Put this formula in M2:

    =SUMPRODUCT(--(DATE(YEAR($F$2:$F$100),MONTH($F$2:$F$100),1)=$L2),G$2:G$100)

    and copy this into N2 (the G range will change to H), then copy both formulae down. Note that you might need to change the ranges, as you will go beyond row 100 if you have more than 3 months' data in the Daily summary table.

    Hope this helps (file attached).

    Pete
    Attached Files Attached Files

+ 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. First date in specific time period based on today's date
    By BanginMyHeadOnMyDesk in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-19-2016, 05:28 AM
  2. Count of date ranges over any given time period.
    By happyj in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 12-15-2014, 03:50 PM
  3. Replies: 0
    Last Post: 07-25-2013, 10:03 AM
  4. Formula to look up value in specific time period
    By chintanbtech in forum Excel General
    Replies: 0
    Last Post: 01-17-2012, 12:44 PM
  5. Replies: 11
    Last Post: 05-20-2011, 02:09 PM
  6. Specific time period calculation from a time range
    By Khaldon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-18-2011, 06:44 AM
  7. Replies: 2
    Last Post: 04-27-2011, 08:21 AM

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