+ Reply to Thread
Results 1 to 8 of 8

Extracting HOUR from a timestamp in SUMIFS statement

  1. #1
    Registered User
    Join Date
    02-10-2017
    Location
    Surrey, UK
    MS-Off Ver
    2010
    Posts
    3

    Extracting HOUR from a timestamp in SUMIFS statement

    Hello all,

    I have a problem that has been driving me mad - I would be grateful of some help!

    I have a spreadsheet where:
    Column A contains names (text string)
    Coumn B contains costs (numbers)
    Colum C contains a timestamp in the format dd/mm/yy hh:mm:ss

    I want to be able to create a formula that says "add up all the costs from Column B, where Column A contains 'DAR' within the string, and the hour is less than 12pm regardless of what the day/date is"

    I used the following fomula, but I keep getting a 0 returned:

    =SUMIFS(B:B,A:A,"*DAR*",C:C,HOUR(C:C)<12)

    The dates in the C column are across multiple days, but essentially I am trying to 'ignore' the days and add up all costs that happen before 12pm - irrespective of what day they happen on.

    I also tried using a SUMPRODUCT statement, but that equally drove me to the brink of insanity.

    I would be most grateful if someone could help. I have a tight deadline coming up, so any help as soon as possible would be much appreciated!

    Thanks and kind regards

    Darren

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

    Re: Extracting HOUR from a timestamp in SUMIFS statement

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

    the word should be without * * (means full length like DARREN or something like that)

  3. #3
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,908

    Re: Extracting HOUR from a timestamp in SUMIFS statement

    Create helper column D:

    D2: =MOD(C2,1) and copy down.

    Try this:

    =SUMIFS(B:B,A:A,"*DAR*",D:D,"<0.5")

  4. #4
    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,193

    Re: Extracting HOUR from a timestamp in SUMIFS statement

    Try

    =SUMPRODUCT((B1:B100)*(ISNUMBER(SEARCH("DAR",A1:A100)))*(HOUR(C1:C100)<12))

    With SUMPRODUCT use defined ranges rather than whole columns

    SUMIF won't work as you need to "separate" out the time from the date: you could add a helper column to do that ..

    use

    =MOD(C1,1) and format as hh:mm

    Then use (with helper in column H)

    =SUMIFS(B:B,A:A,"*DAR*",H:H,"<0.5")

    Excel time is a number 0 to 1 so 12 midday is 0.5

  5. #5
    Registered User
    Join Date
    02-10-2017
    Location
    Surrey, UK
    MS-Off Ver
    2010
    Posts
    3

    Re: Extracting HOUR from a timestamp in SUMIFS statement

    Hi sandy666 and Phuocam

    Thanks so much for your quick replied, however it doesn't quite get to where I need it to be.

    Sandy666 - I may be misunderstand what you say above, but I used your formula, it only matches for the exact text string. So if I put in 'Darren' it picks out anything that is equal to 'Darren'. What I need it to do is pick out anything with 'Dar' in it, so if 'Darren' and 'Darwin' were in the list of strings, it would pick those out as matches as they have 'Dar' in them.

    Phuocam - your method works a treat, but is there a way to do this without a helper column?

    Thanks again

    Darren

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

    Re: Extracting HOUR from a timestamp in SUMIFS statement

    Use John's SUMPRODUCT formula. It works with * *

  7. #7
    Registered User
    Join Date
    02-10-2017
    Location
    Surrey, UK
    MS-Off Ver
    2010
    Posts
    3

    Re: Extracting HOUR from a timestamp in SUMIFS statement

    Hi John

    Thanks for your formula - it works a treat. As a side question, is there any technical reason that I can't use full column references, as opposed to a specific range? The reason I ask is because I have this formula in a 'summary' sheet, but the data is being pulled from a separate sheet. Each month, I will paste new data into the 'data' sheet, but I don't know how many rows will be in it from month to month. There for, I was trying to get around using a specific range.

    Thoughts?

    Thanks again for your help

    Darren

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

    Re: Extracting HOUR from a timestamp in SUMIFS statement

    Do you really have 1,048,576 rows of data? You can use 100 more than you have filled rows or your Excel will be slow, very slow and down at the end

    or use Excel Table and NAMES as dynamic range
    Last edited by sandy666; 02-10-2017 at 06:19 AM.

+ 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: 8
    Last Post: 10-30-2016, 03:44 PM
  2. [SOLVED] Match timestamp to a 24-hour period beginning at 6:00 AM
    By Jerbinator in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-21-2015, 11:52 AM
  3. [SOLVED] Extracting Only the Minutes from Timestamp
    By fearonc in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-04-2014, 05:45 PM
  4. [SOLVED] Excel 2010 - Extracting hour value from HH:MM:SS time - formatting issue
    By asimbig in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-04-2013, 06:47 AM
  5. [SOLVED] Nested IF AND statement with timestamp and ISERROR Help
    By LearningatWork in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-11-2012, 12:37 PM
  6. Extracting Hour from M/D/Y hh:mm
    By Lram in forum Excel General
    Replies: 1
    Last Post: 08-18-2011, 07:49 PM
  7. If/then Statement + timestamp
    By serpent333 in forum Excel General
    Replies: 3
    Last Post: 12-11-2007, 04:50 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