+ Reply to Thread
Results 1 to 11 of 11

Calculate difference between dates only if a condition is met

  1. #1
    Registered User
    Join Date
    02-02-2021
    Location
    Melbourne, Ausralia
    MS-Off Ver
    Office 365
    Posts
    5

    Calculate difference between dates only if a condition is met

    Hello, i'm trying to figure out how to calculate the number of days between dates where a certain condition is met (example of what i'm trying to figure out attached).

    In column D, I want to calculate the difference between only the dates when attendance is yes. e.g. I would want B4 - B2 to inform my frequency result.

    Thanks very much!
    Attached Files Attached Files
    Last edited by hayleyawright; 02-02-2021 at 07:14 PM.

  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,738

    Re: Calculate difference between dates only if a condition is met

    Welcome to the forum.

    What results are you expecting in the frequency column? Manually calculate these for your sample data and add them too the sample workbook, please.
    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
    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,738

    Re: Calculate difference between dates only if a condition is met

    Just a guess, really - is this what you want?

    =MAXIFS($B$2:$B$5,$A$2:$A$5,A2,$C$2:$C$5,"Yes*")-MINIFS($B$2:$B$5,$A$2:$A$5,A2,$C$2:$C$5,"Yes*")

    I had to add the * because you have some trailing spaces in your Yes/No column. Ideally get rid of the trailing spaces and then you can take the * out of the formula.

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,586

    Re: Calculate difference between dates only if a condition is met

    Try this
    In D2 then copy down.

    =IF(C2="Yes",IFERROR($B2-LOOKUP(2,1/($C$1:$C1="Yes"),$B$1:$B1),""),"")
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  5. #5
    Registered User
    Join Date
    02-02-2021
    Location
    Melbourne, Ausralia
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Calculate difference between dates only if a condition is met

    Hi Ali, thanks so much for your help! I have just updated the example spreadsheet (and have removed the trailing space) with the answer I would be looking for. I have added an extra step of just calculating difference between work days (mon - fri) too.

  6. #6
    Registered User
    Join Date
    02-02-2021
    Location
    Melbourne, Ausralia
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Calculate difference between dates only if a condition is met

    Hello, thanks so much you're amazing! How would you go about adding in just NETWORKDAYS into that formula?

  7. #7
    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,738

    Re: Calculate difference between dates only if a condition is met

    Which of us are you asking?

    Try this:

    =IF(C2="Yes",IFERROR(ABS(NETWORKDAYS.INTL($B2,LOOKUP(2,1/($C$1:$C1="Yes"),$B$1:$B1))),""),"")
    Last edited by AliGW; 02-03-2021 at 02:24 AM.

  8. #8
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: Calculate difference between dates only if a condition is met

    Base on your NETWORKDAYS, just replace B2 with:
    LOOKUP(2,1/($A$1:A2=A3)/($C$1:C2="Yes"),$B$1:B2)
    to define the most recent date with "Yes" and same Staff member.

    From D3 (D2 =0):
    Please Login or Register  to view this content.
    Quang PT

  9. #9
    Registered User
    Join Date
    02-02-2021
    Location
    Melbourne, Ausralia
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Calculate difference between dates only if a condition is met

    Thankyou very much - very helpful

    Quote Originally Posted by AliGW View Post
    Which of us are you asking?

    Try this:

    =IF(C2="Yes",IFERROR(ABS(NETWORKDAYS.INTL($B2,LOOKUP(2,1/($C$1:$C1="Yes"),$B$1:$B1))),""),"")

  10. #10
    Registered User
    Join Date
    02-02-2021
    Location
    Melbourne, Ausralia
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Calculate difference between dates only if a condition is met

    Thank-you!!

    Quote Originally Posted by bebo021999 View Post
    Base on your NETWORKDAYS, just replace B2 with:
    LOOKUP(2,1/($A$1:A2=A3)/($C$1:C2="Yes"),$B$1:B2)
    to define the most recent date with "Yes" and same Staff member.

    From D3 (D2 =0):
    Please Login or Register  to view this content.

  11. #11
    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,738

    Re: Calculate difference between dates only if a condition is met

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon 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 those who helped.

+ 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. Dates Difference with condition
    By smartkrawler in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-14-2018, 05:18 PM
  2. if condition for dates difference
    By vimalanathk in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-07-2017, 11:56 PM
  3. Difference in Dates, with Default Condition
    By bdav1216 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-24-2017, 10:41 AM
  4. how to Calculate the difference between two times and apply <= to the condition
    By student_query in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-07-2013, 08:10 PM
  5. Calculate difference in dates
    By papaexcel in forum Excel General
    Replies: 9
    Last Post: 07-27-2009, 02:43 PM
  6. Calculate difference between dates
    By mprice1988 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-25-2008, 01:32 PM
  7. Calculate Difference b/e 2 dates.
    By scharee in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 08-02-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